Dlookup help please. (1 Viewer)

hully333

Registered User.
Local time
Today, 14:19
Joined
Feb 7, 2008
Messages
18
I have produced a dlookup to grab the telephone number of a contact on a form and it returns the folloing error;

run time error '3075': syntax error (missing operator) in query expression ......

Heres the code;
lookup = DLookup("[contact_tele]", "[contacts]", "[contact_name] = " & user)

I cant see whats wrong with it and have cross checked the help on it.
It looks for the contact telephone number from the contacts table where the contact name is that from the variable called user, It then sets a text box on the form to the value of the lookup variable. The error quotes the actual contact when displaying the message box.

Any help would be great.
 

namliam

The Mailman - AWF VIP
Local time
Today, 15:19
Joined
Aug 11, 2003
Messages
11,695
Because your contact_name is probably a text field you need to use quotes around the user name

Like so:
DLookup("[contact_tele]", "[contacts]", "[contact_name] = '" & user & "'")
 

hully333

Registered User.
Local time
Today, 14:19
Joined
Feb 7, 2008
Messages
18
Many thanks that solved the issue.

A little typo though, heres how it looks;
lookup = DLookup("[contact_tele]", "[contacts]", "[contact_name] = " & "'" & user & "'")
 

DCrake

Remembered
Local time
Today, 14:19
Joined
Jun 8, 2005
Messages
8,632
Simple Software Solutions

As you have resloved your little problem and might not read this again, I aim this comment at other users. Don't use a variable name called user this may conflict with reserved words in Access.
 

Users who are viewing this thread

Top Bottom