ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   XL2K: ADO's Find method (once again.) (https://www.excelbanter.com/excel-programming/305476-xl2k-ados-find-method-once-again.html)

Mike Mertes

XL2K: ADO's Find method (once again.)
 
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



merjet

ADO's Find method (once again.)
 
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




Myrna Larson

XL2K: ADO's Find method (once again.)
 
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)


On Thu, 29 Jul 2004 14:11:28 -0400, "Mike Mertes"
wrote:

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




All times are GMT +1. The time now is 02:46 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com