Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Search Box in Form Header 1

Status
Not open for further replies.

Dom606

IS-IT--Management
Jul 29, 2007
123
US
I have the following code on a form to look up last names that sound like XXXXX. The code works but only finds the first occurance. Can anyone tell me how to modify this code to show all the records that meet the search criteria.
Thanks
Dom



Code:
Option Compare Database
Option Explicit

Sub txtFindIt_AfterUpdate()

    Dim objTabs As Object
    Dim stLike As String
    Dim rs As Recordset
    Dim db As Database
    Dim ws As Workspace
    Dim BkMark As String
    Dim Criteria$
    Dim cFindWhat As String

     cFindWhat = Me.txtFindit & " " 'The empty Space avoids a possible Null error

    Me.Painting = False
    Set db = DBEngine(0)(0)
    Set ws = DBEngine.Workspaces(0)
    Set rs = Me.RecordsetClone 'Make a clone to look up values

    BkMark = Me.Bookmark   'Mark where we are now
     stLike = "'" & Trim(cFindWhat) & "*'" 'Add the wildcard..
     Criteria$ = "LastName Like " & stLike

        rs.MoveFirst
        rs.FindFirst Criteria$

       If Not rs.NoMatch Then
         BkMark = rs.Bookmark

        End If

      Me.Bookmark = BkMark
      rs.Close
      Me.Painting = True
      DoCmd.Hourglass False
      Me.txtFindit = ""

End Sub
 
I don't understand why you are using recordsets and bookmarks since they typically reference a single record.

Have you considered simply setting the filter property
Code:
Sub txtFindIt_AfterUpdate()
  If Not IsNull(Me.txtFindIt) Then
    Me.Filter = "LastName Like """ & Me.txtFindIt & "*"""
    Me.FilterOn = True
   Else
    Me.FilterOn = False
  End If
End Sub

Duane
Hook'D on Access
MS Access MVP
 
Duane,
Thanks you so much. Your code works like a charm. I gave you a star for making things simple.
Well done and appriciated.
Dom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top