Discussion Locked

ADO Find

0 helpful
6 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.
I am working on a project that requires I search for user names form an Access 2000 table. I am using VB 6 wtih the # 4 service pack installed. I can view records ok. But I cannot get the find command to work, here is the line Me.adoLogin.Recordset.Find "UserId = ' textbox.Text'" the adoLogin is my connection UserId is the field name and the textbox.text is the text bo I want the user to type in thier ID. If I hard code a userId the find works. I have tried to make a string variable and assign the textbox text to that and insert that into the find command.

6 replies

by bill_h

Your example code asks for the Find to look for a value equal to the string "textbox.Text", which does not exist. If you want the Find to look for the text *value* of a text box, use the following syntax:

Me.adoLogin.Recordset.Find "UserId='" & textbox.Text & "'"

This submits the value/text of the textbox, enclosed in single quotes. This syntax can also be used with string variables.

To use a numeric value, the following syntax will work:

Me.adoLogin.Recordset.Find "UserId=" & Val(textbox.Text)

There is no need to enclose a numeric value in single quotes; this syntax can also be used with numeric variables.

Hope this helps...

by bill_h

In reviewing my answer, the text displayed on my browser doesn't clearly show the single quotes I included in the example syntax. Let me clarify:

The statement "UserId='" & textbox.Text & "'" contains a *single quote* after the equal sign (=); the double-quoted string at the end is actually a double quote, a single quote and a double quote.

If you cut and paste the code I provided, you be able to see the correct syntax...

by donq

Bill's answer would work fine however you might consider running a query (inside Access) against the table that would alloy you to change your "filters" dynamically where the User ID is selected from a combo box before the query runs. VBA codes directly into Access.

This discussion is closed to new replies.