Before I add a new contact from my form, I want to search to see if any contact exists using the first and last name. I can successfully search with the Dlookup in the code as shown in number 1, below however, when I try to replace the text with variables, #2, below, I get:
Run-Time Error 2471 - The expression you entered as a query parameter produced this error: 'VarFirst'
#1 Successful DLookup
Code:
Private Sub CLastName_AfterUpdate()
'Purpose to find if a Contact Name exists and to use it
'or continue to create a new one.
Dim varFirst As String
Dim varLast As String
Dim varTitle As String
varLast = Me.CLastName
varFirst = Me.CFirstName
Debug.Print varFirst
Debug.Print varLast
varTitle = DLookup("[CTitle]", "tblContacts", "[CLastName] = 'Ale' And [CFirstName] = 'Dan'")
Debug.Print varTitle
End Sub
#2 Unsuccessful
Code:
Private Sub CLastName_AfterUpdate()
'Purpose to find if a Contact Name exists and to use it
'or continue to create a new one.
Dim varFirst As String
Dim varLast As String
Dim varTitle As String
varLast = Me.CLastName
varFirst = Me.CFirstName
Debug.Print varFirst
Debug.Print varLast
varTitle = DLookup("[CTitle]", "tblContacts", "[CLastName] = varLast And [CFirstName] = varFirst")
Debug.Print varTitle
End Sub
I have tried all sorts of variations with the criteria, but non work.
Any Suggestions