• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 134
  • Last Modified:

Find Method Using Classes

Hi,

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?

0
kenmck
Asked:
kenmck
1 Solution
 
rovermCommented:
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,

RoverM
0
 
johnny6Commented:
kenmck:
      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:

http://www.microsoft.com/data/ado/adotechinfo/dao2ado_3.htm

John
0
 
WalterMCommented:
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, _
            adBookmarkFirst

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...).
0
 
kenmckAuthor Commented:
Thanks that works fine.

Ken.
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now