PDA

Click to See Complete Forum and Search --> : Searching databases using VB


brjames
Feb 1st, 2000, 04:11 AM
I'm creating a Lifeguard database and I want to search for details in a table in the associated database table using VB. I have some code but it doesn't seem to be working . What settings do I need to in the 'Indexed' section under Lifeguard Name in design view of the table?

My VB code is below

Thanks


Ben Private Sub cmdSearchbyname_Click()

prompt$ = "Enter the Lifeguard's full name"

SearchStr$ = InputBox(prompt$, "Lifeguard Name Search")
Data1.Recordset.Index = "Name"
Data1.Recordset.Seek "=", SearchStr$
If Data1.Recordset.NoMatch Then
Data1.Recordset.MoveFirst
End If

End Sub

Clunietp
Feb 1st, 2000, 11:12 AM
To speed up searches, you'll want to create an index in the design mode of your access table.

Here is a way to search your recordset/table using DAO:


Dim db As Database

Dim rs As Recordset

Set db = DBEngine.OpenDatabase("Nwind.mdb")

Set rs = db.OpenRecordset("Select * from Customers")

rs.FindFirst "CustomerID = 'ALFKI'"

If rs.NoMatch = True Then
MsgBox "No Match!"
Else
MsgBox rs.Fields("CustomerID").Value
End If

db.Close


HTH

Tom

etta
Feb 5th, 2000, 01:06 AM
Using DAO would be easier. Instead of using
the input box but a text box on the form and
a command button.

text box = txtName
command1 = cmdFind

Private Sub cmdFind_Click()
Dim db As Database
Dim rs As RecordSet
Dim sql As String

sql = "Select * From TableName Where Name =' " & txtName & " ' "

Set db=OpenDatabase(App.Path & "\dbname.mdb")
Set rs=db.OpenRecordset(sql)

End Sub

The results can then be displayed in a DBGrid
or text box.

[This message has been edited by etta (edited 02-05-2000).]

[This message has been edited by etta (edited 02-05-2000).]