Results 1 to 2 of 2
  1. #1
    injanib is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Jan 2011
    Posts
    67

    Search with multiple criteria

    Appreciate your help in advance.



    I got the code below from another forum. It works great for two criteria fields. How can I modify it for three criteria fields?

    Dim strFilter as String

    If (Len(cboCommitteeName) & "") > 0 Then strFilter = "[CommitteeName]='" & cboCommitteeName & "'"
    If (Len(cboStatus) & "") > 0 Then
    If Len(strFilter) > 0 Then strFilter = strFilter & " And "
    strFilter = strFilter & "[Status]='" & cboStatus & "'"
    End If
    Me.Filter = strFilter
    Me.FilterOn = True

  2. #2
    maximus's Avatar
    maximus is offline Expert
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Aug 2009
    Location
    India
    Posts
    931
    Here is a simple example how you can build up a criteria with multiple conditions:

    I have used this criteria to open a form in your case you can use it to Filter your form.


    Dim strcriteria
    'Determining the criteria

    strCriteria = ""


    If Not IsNull(Me.Student_Name) Then
    strCriteria = "Student_Name='" & Me.Student_Name & "'"
    End If
    If Not IsNull(Me.Student_Class) Then
    If Len(strCriteria) > 0 Then
    strCriteria = strCriteria & " And Student_Class='" & Me.Student_Class & "'"
    Else
    strCriteria = "Student_Class='" & Me.Student_Class & "'"
    End If
    End If
    If Not IsNull(Me.Student_Roll) Then
    If Len(strCriteria) > 0 Then
    strCriteria = strCriteria & " And Student_Roll=" & Me.Student_Roll
    Else
    strCriteria = "Student_Roll = " & Me.Student_Roll
    End If
    End If
    If Not IsNull(Me.Student_DOB) Then
    If Len(strCriteria) > 0 Then
    strCriteria = strCriteria & " And Student_DOB=#" & Me.Student_DOB & "#"
    Else
    strCriteria = "Student_DOB=#" & Me.Student_DOB & "#"
    End If
    End If

    'MsgBox strCriteria

    If Len(strCriteria) > 0 Then
    DoCmd.OpenForm "Table3", , , strCriteria
    Else
    MsgBox "Please select Criteria"
    Exit Sub
    End If

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Search for multiple records
    By Blake in forum Queries
    Replies: 1
    Last Post: 08-23-2013, 03:17 AM
  2. Search Button with Multiple Criteria
    By injanib in forum Forms
    Replies: 2
    Last Post: 01-12-2011, 02:21 AM
  3. search criteria in a form fails!
    By maxbre in forum Programming
    Replies: 2
    Last Post: 12-01-2010, 06:21 AM
  4. Replies: 4
    Last Post: 09-22-2010, 01:47 AM
  5. How can I search multiple tables?
    By botts121 in forum Access
    Replies: 4
    Last Post: 02-02-2010, 06:39 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums