|
-
Mar 19th, 2010, 06:55 PM
#1
Thread Starter
Member
How to build a Count Querie for VBA code
I'm fixing a software from an old source code. the code is here but the query in the database is not there anymore. I just want the software to keep adding a number every time i input a two customers with the same name. This is the code i have on the source
Private Sub cmdCheck_Click()
Dim q As QueryDef
Dim rs As Recordset
Dim CountStr As String
Dim Count As Long
If Len(txtFirstName) = 0 Then
MsgBox "Please enter a first name", vbCritical, "F-Miracle"
Exit Sub
End If
If Len(txtLastName) = 0 Then
MsgBox "Please enter a last name", vbCritical, "F-Miracle"
Exit Sub
End If
Set q = CurrentDB.QueryDefs("int_qGetCodeCount")
q.Parameters("pCode") = UCase(MakeCode)
Set rs = q.OpenRecordset
If rs.RecordCount = 0 Then
Count = 1
Else
Count = rs("MaxCode") + 1
End If
CountStr = Format(Count, "000")
txtCode = UCase(MakeCode) & CountStr
cmdSave.Enabled = True
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|