Results 1 to 4 of 4
  1. #1
    2 Star Lounger
    Join Date
    Apr 2005
    Location
    Plovdiv
    Posts
    109
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Search by name (Access 2000)

    Which is the best method to ensure a search for the product beginning with the first letters till the product is found? This property is embedded into Acess but i have met somewhere in the present Forum a code which i cannot find,
    now,but concerns a quick finding the name of the person by writing the first letters. I cannot find the thread but it was an excellent code
    Thank you for the help

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Search by name (Access 2000)

    You can use the On Change event of an unbound text box. Let's say that the text box is named txtSearch, and that the field to search is named ProductName. Here is code to use for moving to a record as the user types.

    Private Sub txtSearch_Change()
    Dim rst As DAO.Recordset
    Dim strSearch As String

    On Error GoTo ErrHandler

    If IsNull(Me.txtSearch) Then Exit Sub

    Set rst = Me.RecordsetClone
    strSearch = "[ProductName] Like " & Chr(34) & Me.txtSearch.Text & "*" & Chr(34)
    rst.FindFirst strSearch
    If rst.NoMatch Then
    Beep
    Else
    If Me.Dirty Then RunCommand acCmdSaveRecord
    Me.Bookmark = rst.Bookmark
    End If

    ExitHandler:
    Me.txtSearch.SelStart = Len(Me.txtSearch.Text)
    Exit Sub

    ErrHandler:
    MsgBox Err.Description, vbExclamation
    Resume ExitHandler
    End Sub

    Make sure that you have a reference to the Microsoft DAO 3.6 Object Library in Tools | References... in the Visual Basic Editor.

  3. #3
    2 Star Lounger
    Join Date
    Apr 2005
    Location
    Plovdiv
    Posts
    109
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Search by name (Access 2000)

    Thank you for the reply.I have copied your code refered it to DAO3.6, but the unbound control does not function.What is the reason?Obviously i did not understand you right.Therefore i am applying the example
    regards

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Search by name (Access 2000)

    Sorry, my mistake. Change the line

    If IsNull(Me.TxtSearch) Then Exit Sub

    to

    If Me.TxtSearch.Text = "" Then Exit Sub

    Note: you'll have to add some controls bound to fields in the Products table to the form, otherwise you won't see the result.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •