stLinkCriteria Question

  • Thread starter Thread starter Guest
  • Start date Start date
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.
 
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.
 
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.
 
Back
Top