|
-
Feb 1st, 2000, 05:11 AM
#1
Thread Starter
Lively Member
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
-
Feb 1st, 2000, 12:12 PM
#2
Guru
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:
Code:
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
-
Feb 5th, 2000, 02:06 AM
#3
New Member
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).]
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|