8 Years
Discussion Span
Last Post by vbboy


Are you talking about searching specific data in a database?

Please tell us more in specifics on what you need to search for.


need more information. what kind of search you want? from database, from text file or other?


Well, there is quite a few ways depending on WHAT you want to search for. Below is a few samples -

rs.Open "Select FirstName,LastName,Balance from Patients Where Balance > 0", cn, adOpenKeyset, adLockOptimistic
'Will search for a monetary value.

rs.Open "Select FirstName,LastName,Gender,City,ID from Patients Where Gender='Female' and City='Cape Town'", cn, adOpenKeyset, adLockOptimistic
'Will search for a gender or city

rs.Open "Select FirstName,LastName,FirstVisitDate from Patients Where FirstVisitDate >= DateValue('1/1/2009')", cn, adOpenKeyset, adLockOptimistic
'Will search for a specific date.

rs.Open "Select * from Patients Where left(FirstName,1)='E'", cn, adOpenKeyset, adLockOptimistic
'Will search for all names starting with "E".

rs.Open "Select FirstName,LastName,Diagnosis from Patients", cn, adOpenKeyset, adLockOptimistic
rs.Filter = "Diagnosis Like '*Stomach Pain*'"
'Will search for any name where either stomach or pain is in the data.

I hope this helps in searching for the correct data.

Happy coding.


Hi soilarmoon, may also use this code from this site

Hopefully it may help.

Function Search_Data()
On Error GoTo errHandler
Dim mSQL$
mSQL = “Select Code,Name,Address From Supplier Where Code Like ‘%” & text1 & “%’ Or Name Like ‘%” & text1 & “%’ ” & _
” Or Address Like ‘%” & t & “%’ Order by Name Asc ”
Adodc1.ConnectionString = ConStr
Adodc1.CommandType = adCmdText
Adodc1.RecordSource = mSQL
Set dg1.DataSource = Adodc1
cmdOK.Enabled = True
If Adodc1.Recordset.BOF And Adodc1.Recordset.EOF Then
cmdOK.Enabled = False
End If
Exit Function
MsgBox CStr(Err.Number) + Err.Description

End Function

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.