XL2K: ADO's Find method (once again.)

M

Mike Mertes

Maybe no one understood what I was asking before, so let me try this again:

In this example:

recordset.Find "FIELD = 'MyVar'"

What is the correct syntax for replacing the literal string, "MyVar," with a
variable?
I've tried every way I could think of, and I always get a syntax error as
the result.

For instance:

Dim MyVariable as String
recordset.Find "FIELD = MyVariable"

does not work.

TIA,
Mike
 
M

merjet

Hi Mike,
In this example:

recordset.Find "FIELD = 'MyVar'"

What is the correct syntax for replacing the literal string, "MyVar," with a
variable?
I've tried every way I could think of, and I always get a syntax error as
the result.

A workaround is to fully specify the argument in advance, e.g.

Dim str As String
' if MyVar is a String:
str = Chr(34) & "Field ='" & Chr(34) & MyVar & Chr(34) & "'" & Chr(34)
' if MyVar is numeric:
str = Chr(34) & "Field ='" & MyVar & "'" & Chr(34)
rs.Find str

HTH,
Merjet
 
M

Myrna Larson

I don't know if this will work, but try

"FIELD = '" & MyVariable & "'"

or, a trick that I often use

recordset.Find Replace("FIELD = 'MyVar'", "MyVar", MyVariable)
 

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