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