Tuesday, November 16, 2010

How to search a record in VB 6 ado?

I have linked my access database in VB using ado. The records show in the listbox named lstrecords. I want to be able to type in a keyword in the text box and when i click the search button, i want the results to be displayed in the listbox. I dnt mind if the whole table gets searched or just one field. Can anybody help? thanksHow to search a record in VB 6 ado?
If the text box is called txtKeyWord, on form YourForm, then in the SearchButton OnCLick event handler, create a dynamic SQL statement: the aim is to produce the criteria



Is Like ';*keyword*';



strSQL = SELECT fields, etc FROM Table WHERE (FieldName Is Like '*'; %26amp; Forms![YourForm]!txtKeyWord] %26amp; ';*');';



etcHow to search a record in VB 6 ado?
Select %26lt;the field you want to display%26gt; from %26lt;the table name%26gt; where %26lt;the field to be searched%26gt; = '%26lt;the input from the user%26gt;';



Open the recordset with that string (build it from the user input) and display the resulting records.

No comments:

Post a Comment