Results 1 to 3 of 3
  1. #1
    4 Star Lounger
    Join Date
    May 2003
    Location
    Manchester, Gtr Manchester, England
    Posts
    552
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Searching for records (2000)

    Hello some time back, moderator Hans kindly provided me with code by which my users could search for records in my database. The code did and does a splendid job opn the DB it was intended for, I now have another project and have adapted that code. It still works but only to point, in essence if a user wishes to search by a number of fields, they type in or select from a combo as necessary and after update the first record created to match the search details is displayed. For my new project I need it to go to all records that meet the search criteria. The existing code is pasted below. Can anybody please offer me some guidance?

    Many thanks Darren

    Private Function DoSearches()
    Dim rs As Object
    Dim strFilter As String

    ' Assemble filter string

    ' Field1 is numeric
    If Not IsNull(Me.Tccs) Then
    strFilter = strFilter & _
    " And [Tcc] = " & Me.Tccs
    End If

    ' Field2 is a date
    If Not IsNull(Me.DateX) Then
    strFilter = strFilter & _
    " And [date] = #" & Format(Me.DateX, "mm/dd/yy") & "#"
    End If

    If strFilter = "" Then
    ' Nothing to search for
    Exit Function
    End If

    ' Get rid of first " And "
    strFilter = Mid(strFilter, 6)

    ' This is the search code
    Set rs = Me.Recordset.Clone
    rs.FindFirst strFilter
    If rs.NoMatch Then
    MsgBox ("No Record Found")
    Else
    Me.Bookmark = rs.Bookmark
    End If


    Set rs = Nothing

    End Function

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

    Re: Searching for records (2000)

    I assume that by "go to all records" you mean that you want to set a filter on the form.

    Remove the line Dim rs As Object, and replace the code after "This is the search code" with:

    Me.Filter = strFilter
    Me.FilterOn = True
    End Sub

  3. #3
    4 Star Lounger
    Join Date
    May 2003
    Location
    Manchester, Gtr Manchester, England
    Posts
    552
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Searching for records (2000)

    Thanks Hans.

    Darren.

Posting Permissions

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