stLinkCriteria Question

G

Guest

I use the following code to permit users to search for records by last name
on a form.

stLinkCriteria = "[Last_Name] Like " & "'" & Me![txtNameLast] & "*'"

I would like to add additional criteria to the above so they could search by
last and first name combined. I tried the following but it generates a type
mismatch error

stLinkCriteria = "[Last_Name] Like " & "'" & Me![txtNameLast] & "*'" And
"[First_Name] Like " & "'" & Me![txtNameFirst] & "*'"

Any help appreciated in telling me what I am doing wrong. Thanks.
 
M

Marshall Barton

Janna said:
I use the following code to permit users to search for records by last name
on a form.

stLinkCriteria = "[Last_Name] Like " & "'" & Me![txtNameLast] & "*'"

I would like to add additional criteria to the above so they could search by
last and first name combined. I tried the following but it generates a type
mismatch error

stLinkCriteria = "[Last_Name] Like " & "'" & Me![txtNameLast] & "*'" And
"[First_Name] Like " & "'" & Me![txtNameFirst] & "*'"

Any help appreciated in telling me what I am doing wrong. Thanks.


The AND must be inside the quotes. It's part of the
criteria, not part of the expression used to contruct the
criteria.

stLinkCriteria = "[Last_Name] Like """ & Me!txtNameLast & _
"*"" And [First_Name] Like """ & Me![txtNameFirst] & "*"""

I change your use of apostrophes to quotes to avoid problems
with names like O'Brian.
 
G

Guest

Thanks!--Just what I needed :)

Marshall Barton said:
Janna said:
I use the following code to permit users to search for records by last name
on a form.

stLinkCriteria = "[Last_Name] Like " & "'" & Me![txtNameLast] & "*'"

I would like to add additional criteria to the above so they could search by
last and first name combined. I tried the following but it generates a type
mismatch error

stLinkCriteria = "[Last_Name] Like " & "'" & Me![txtNameLast] & "*'" And
"[First_Name] Like " & "'" & Me![txtNameFirst] & "*'"

Any help appreciated in telling me what I am doing wrong. Thanks.


The AND must be inside the quotes. It's part of the
criteria, not part of the expression used to contruct the
criteria.

stLinkCriteria = "[Last_Name] Like """ & Me!txtNameLast & _
"*"" And [First_Name] Like """ & Me![txtNameFirst] & "*"""

I change your use of apostrophes to quotes to avoid problems
with names like O'Brian.
 

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