Results 1 to 2 of 2
  1. #1
    Join Date
    Jun 2009

    Unanswered: MS Access VBA Filter


    Im new here and im not sure if this is the correct place for this to go, but here goes..

    i have a search box which allows me to search but when i click show results it only filters out the first criteria.


    i search for John Smith

    when i click show results it only filters as the following

    Staff.[Contact First]='John'

    but i would like it to filter the following

    Staff.[Contact First]='John' AND Staff.[Contact Last]='Smith'

    this is my VBA coding which i have

    DoCmd.OpenForm "All", , , _
    "Staff.[Contact First]=" & "'" & Me.[Contact First] & "'"

    DoCmd.Close acForm, "Search"

    End Sub

    so i think somewhere i need to add the following line

    "Staff.[Contact Last]=" & "'" & Me.[Contact Last] & "'"

    but im unsure where and how to do this.


    - DreamOn
    Last edited by DreamOn01; 06-16-09 at 10:28.

  2. #2
    Join Date
    May 2005
    Why not:
    dim strFilter as string
    strFilter = ""Staff.[Contact First] = '" & Me.[Contact First] & "' AND " & _
            "Staff.[Contact Last] = '" & Me.[Contact Last] & "'"
    DoCmd.OpenForm "All", , , strFilter

    For help on building SQL strings in VBA, I'd recommend this.
    Me.Geek = True

Posting Permissions

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