Searching for a Record
Posted on 2004-11-14
I am working with VB6 linked to an Access database via the Data button control. I can view the records and skip through them with the arrows on the Data control, so surely there must be an easy way to search the recordset. I have tried to use this:
FindPN = InputBox("Enter Part Number")
If FindPN = "" Then
Data1.Recordset.FindFirst "partno LIKE ' " & FindPN & "%'"
If Data1.Recordset.EOF Then
MsgBox "No titles in the database match your criteria"
This works, but it only finds the first record (of course - thought I'd get away with that). Is it possible to try Seek or Filter instead of FindFirst? How about making the value entered in the Input Box the first record?
I've also tried (in another form):
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Set cn = New ADODB.Connection
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\jsdegard\Desktop\PieceWeight.mdb;User Id=admin;Password=;"
Set rs = New ADODB.Recordset
rs.CursorLocation = adUseClient
rs.Open "Select * From tblmain Where Text1='" & Text0.Text & "'", cn, adOpenKeyset, adLockOptimistic, -1
Here I tried to match a value in an unbound text box 'Text0' to a record in tblmain with field 'Text1.' I get an error 'no value given for one or more required parameters.' Frankly, I've twisted this method in so many ways to no avail that I've about given up on it. But If you see something I don't let me know. Otherwise, the first set of code in this post has been more friendly -I'd like to try to make that work. Any response to my situation would be more than helpful.
Thanks in advance.