How to use DLOOKUP with the Like * Functions

D

dbarmer

I have a form with a command button, when chosen goes to vba code. Within
this code I have a InputBox asking the user for a Employee name with a string
variable named 'SearchString'. I want to take that expression and 'Dlookup'
to a table, with the LIKE function, where the 'SearchString' does not have to
be the full text of the fieldname 'Employee'

I get a syntax error while writing it, can't seem to get the "LIKE *
function to work.

HELP?
 
D

Douglas J. Steele

It's not clear to me whether or not the user is typing the wildcard
character into the InputBox.

If they are, you need code along the lines of:

DLookup("[NameOfField]", "[NameOfTable]", "[EmployeeName] Like """ &
SearchString & """")

That's 3 double quotes in front of SearchString, and 4 double quotes
afterwards. (You need to use the double double quotes rather than a single
quote to allow for names with apostrophes in them, like O'Reilly)

If they aren't including the wildcard character, use

DLookup("[NameOfField]", "[NameOfTable]", "[EmployeeName] Like """ &
SearchString & """*")

or

DLookup("[NameOfField]", "[NameOfTable]", "[EmployeeName] Like "*"" &
SearchString & """*")
 
D

dbarmer

Thanks! - That did the trick!!!

Douglas J. Steele said:
It's not clear to me whether or not the user is typing the wildcard
character into the InputBox.

If they are, you need code along the lines of:

DLookup("[NameOfField]", "[NameOfTable]", "[EmployeeName] Like """ &
SearchString & """")

That's 3 double quotes in front of SearchString, and 4 double quotes
afterwards. (You need to use the double double quotes rather than a single
quote to allow for names with apostrophes in them, like O'Reilly)

If they aren't including the wildcard character, use

DLookup("[NameOfField]", "[NameOfTable]", "[EmployeeName] Like """ &
SearchString & """*")

or

DLookup("[NameOfField]", "[NameOfTable]", "[EmployeeName] Like "*"" &
SearchString & """*")


--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


dbarmer said:
I have a form with a command button, when chosen goes to vba code. Within
this code I have a InputBox asking the user for a Employee name with a
string
variable named 'SearchString'. I want to take that expression and
'Dlookup'
to a table, with the LIKE function, where the 'SearchString' does not have
to
be the full text of the fieldname 'Employee'

I get a syntax error while writing it, can't seem to get the "LIKE *
function to work.

HELP?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top