I have a form. It has a combo box for persons last name. The form also has a button called client search. I have some code that I pieced together from reading online.
A name is selected from the combo box, you hit the search button and a form will be launched with the selected persons information. It works fine. The data I'm working with in my table is ID(text), FirstName(text), LastName(text). I want the ID in the table to be an number. If I change the data type to a number I get the mismatch error. I don't know enough about VB to figure this out. Help would be appreciated.
Private Sub Command4_Click()
Dim strSQL As String
If Not Nz(cbxLastName) = "" Then strSQL = strSQL & " And [LastName]='" & cbxLastName & "'"
strSQL = Mid(strSQL, 6)
If strSQL = "" Then
MsgBox "Please enter at least one criteria field.", vbExclamation
Exit Sub
End If
Dim strID As String
strID = Nz(DLookup("ID", "[Table1]", strSQL))
If strID = "" Then
MsgBox "No match!", vbExclamation
Exit Sub
End If
FindClient "Client Auth Info", strID
End Sub
Private Sub FindClient(strFormName, strID As String)
DoCmd.OpenForm strFormName
Dim rs As Recordset
Set rs = Forms(strFormName).RecordsetClone
rs.FindFirst "ID='" & strID & "'"
If Not rs.NoMatch Then Forms(strFormName).Bookmark = rs.Bookmark
End Sub
The bolded line. Run time error 3464: Data type mismatch in criteria expression.
Works with ID field as text, error when set as number. I would like this to work with the ID data type as number.
Thanks.