DLookup for multiple criteria

Malcy

Registered User.
Local time
Today, 22:59
Joined
Mar 25, 2003
Messages
584
Hi
I am wanting a DLookup to check to see if a contact is already listed in a table.
I reckon I am OK using their forename, surname and first address line.
I have currently got, but know it isn't working and am at a loss to work out which bit(s) are wrong:
Code:
intConId = DLookup("lngConId", "tblContacts", "[strConSname] = " & "'" & Me.txtSname & "'" And "[strConFname] = " & "'" & Me.txtFname & "'" And "[strConAdd1] = " & "'" & Me.txtAddr1 & "'")
All three fields are text strings.
If some SQL whizz could sort me out I would be most appreciative. I am afraid I really struggle with these. Seem to have almost got the hang of a single criteria but this one has me stumped!
Any help appreciated
Thanks and best wishes
 
DLookup("[lngConId]", "tblContacts", "[strConSname] = '" & Me.txtSname & "' And [strConFname] = '" & Me.txtFname & "' And [strConAdd1] = '" & Me.txtAddr1 & "'")

???
kh
 
"AND" must be within the quotes; only the form references are outside. Try this (I like keeping the single quotes inside the main quotes rather than separate, but that's me):

Code:
intConId = DLookup("lngConId", "tblContacts", "[strConSname] = '" & Me.txtSname & "' And [strConFname] = '" & Me.txtFname & "' And [strConAdd1] = '" & Me.txtAddr1 & "'")

Edit: Sorry Ken, you were too quick for me.
 
pbaldy said:
"AND" must be within the quotes; only the form references are outside. Try this (I like keeping the single quotes inside the main quotes rather than separate, but that's me):

Code:
intConId = DLookup("lngConId", "tblContacts", "[strConSname] = '" & Me.txtSname & "' And [strConFname] = '" & Me.txtFname & "' And [strConAdd1] = '" & Me.txtAddr1 & "'")

Edit: Sorry Ken, you were too quick for me.


I'm surprised mile didn't jump in... :p
 
Hi guys
Thanks for such a prompt response - how do you follow this stuff!!!
I ended up using Paul's suggestion simply because I came to it first and it works a treat.
Thanks a lot for your help. One day I will get to follow the apparently convoluted logic!
Best wishes from a very wet Edinburgh. Just very glad I am not at the Tatoo since would get drowned!
 

Users who are viewing this thread

Back
Top Bottom