How to search data in Visual Basic 6?
Adding a search button on your system is such a good idea, It depends on you what is "Searchable" on your system, it can be: Customer Code/Item Code/Last Names/ etc.... Here in this method I used Customer No. as searchable string.
The Code:
Private Sub cmdsearchnow_Click()
Dim CN As ADODB.Connection
Dim rs As ADODB.Recordset
Dim Y As Integer
On Error Resume Next
OpenDataFiles CN, rs, "YOURDATABASE.MDB", "SELECT * FROM CUSSTOMERS ORDER BY LASTNAME"
If Not rs.BOF And rs.EOF Then
rs.MoveFirst
End If
c = 0
Do While Not rs.EOF
If rs!CustomerNo= txtSearchCustomer.Text Then
With rs
txtpassbookno.Text = !passbookno
'Place all rs here to appear on textbox after search.
c = 1
End With
End If
If c = 1 Then
End If
rs.MoveNext
Loop
If c = 0 Then 'if no match to the access database (return false)
MsgBox "Sorry Record not found..."
Exit Sub
End If
' Call cleared 'this is optional, you can create on later.
End Sub