Jobs
Author: zMastaa Date Submitted: 3/15/2006 Category: Database Compatibility: VB 6,VB 5 This code has been accessed 20462 times.
Email Yourself this snippet:
'Make a button named "cmdSearch 'Listbox as "list1" 'Textbox called "txtSearch" 'adodc as "adodc1" 'edit the database code after recordsource to your need
Code
Private Sub cmdSearch_Click() List1.Clear Dim search As String Dim Clientname As String search = txtSearch.Text Adodc1.CommandType = adCmdText Adodc1.RecordSource = "SELECT * from database-name WHERE [table] LIKE '%" & search & "%'" Adodc1.Refresh If Adodc1.Recordset.EOF Then MsgBox "No record found matching " & search & "!!!" Else Adodc1.Recordset.MoveFirst End If List1.Clear Do Until Adodc1.Recordset.EOF List1.AddItem (Adodc1.Recordset.Fields(1)) Adodc1.Recordset.MoveNext Loop If Adodc1.Recordset.EOF And Adodc1.Recordset.RecordCount > 1 Then MsgBox "Records Found" End If End Sub