Syntax Error with FindFirst Method

E

Eric

I'm getting a syntax error using the findfirst
method using multiple criteria.

.FindFirst "LastName ='" & rstout!LastName & "'" & "
And FirstName = '" & rstout!FirstName & "'"

Does anyone see what i'm doing wrong here?

TIA.
 
M

Marshall Barton

Eric said:
I'm getting a syntax error using the findfirst
method using multiple criteria.

.FindFirst "LastName ='" & rstout!LastName & "'" & "
And FirstName = '" & rstout!FirstName & "'"

Does anyone see what i'm doing wrong here?


Looks OK to me. I'm wondering which name it failed on. If
the name has an apostrophe in it (e.g. O'Riley), you will
get that error because of the unbalanced ' marks. You could
try using " marks instead since they rarely occur in names.

..FindFirst "LastName =""" & rstout!LastName & _
""" And FirstName = """ & rstout!FirstName & """"

Otherwise, you'll have to use the Replace function to double
up the quotes use to enclose the names.

..FindFirst "LastName ='" & _
Replace(rstout!LastName, "'", "''") & _
"' And FirstName = '" & _
Replace(rstout!FirstName, "'", "''") & "'"

When these expressions get too difficult to analyze, add a
Debug.Print or MsgBox to display the result of all that
concatenation so you can see what ended up being used.
 
A

Alex Dybenko

to avoid mess in quotes try the following:
declare a constant

const cQT="""" '(4 double quotes)

then your line will look like:
..FindFirst "LastName =" & cqt & rstout!LastName & cqt & " And FirstName = "
& cqt & rstout!FirstName & cqt
 

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