Find Method Using Classes


I have a single record form which displays one record at a time from an Access database using a class binding type.

I would like to build in to my form a find facility. i.e The user would input the product number and press ok, and the form would automatically move to the record selected.

Can anyone help?

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

place a DBGrid and a ADODC on your form,
connect the ADODC to to DBGrid.
In the Click event of the search button:

ADODC1.Recordset.Filter = "searchfield = " & Text1.Text

where 'searchfield' is the field in your database containing the product number and Text1 is the textbox containing the user input.

The grid now only displays the searched record.

You can set the ADODC to Visible = False if you like.

Good luck,

      You will see an example of how to use the find method using DAO and another example of the find method using ADO at the following link:

If all controls on the form are bound to the same recordset, you can simply reposition using the Find method. The controls will update automatically, just as they do when you execute a MoveNext command.

Say the user inputs an ID in a textbox called txtID and then presses command button cmdOK, and the ID field in the database is called "ID". Then use code like this in the button's Click event:

Private Sub cmdOK_Click

   rst.Find "ID = " & txtID, _
            0, _
            adSearchForward, _

End Sub

If you've encapsulated the recordset into a class, just add a Find method to the class which calls the original recordset Find method.

Good Luck!

Michel Rutten

BTW I presume you are using ADO (if not, you should...).

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
kenmckAuthor Commented:
Thanks that works fine.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.