Results 1 to 3 of 3

Thread: Searching databases using VB

  1. #1

    Thread Starter
    Lively Member brjames's Avatar
    Join Date
    Jan 2000
    Location
    Tenby, Wales, UK
    Posts
    121

    Post

    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


  2. #2
    Guru Clunietp's Avatar
    Join Date
    Oct 1999
    Location
    USA
    Posts
    1,844

    Post

    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

  3. #3
    New Member
    Join Date
    Feb 2000
    Posts
    5

    Post

    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
  •  



Click Here to Expand Forum to Full Width