Results 1 to 3 of 3
  1. #1
    Huddle is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Jun 2010
    Posts
    318

    Multiple criteria in a SQL query

    I need some direction on where to start.



    I have a form "Fm_Criteria_Parameter". I have a report "Rpt_Criteria" that I have a SQL query in the Record Source.

    I want the user to put in as much or little criteria on the form that is needed to get their data.

    I understand the formula Form!Fm_Criteria!Combox...will select the parameter for whichever combo box has information in it.

    I also understand that I can not put the formula for each combo box on the "Criteria" line in the query because all criteria would have to be met including the null fields.

    Example: The user enters data in Field 1, 6 & 7 but leaves 2,3,4 & 5 blank. I want to query the data to bring up only the records that meet the criteria entered.

    Can you push me in the right direction on how to accomplish this?

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,742
    Is this the sort of thing you're looking for?
    http://www.fontstuff.com/access/acctut19.htm

    There are other tutorials at the site

  3. #3
    Huddle is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Jun 2010
    Posts
    318
    Using the examples in the tutorial I've have the below created. My problem is the code for applying the filter to the report and switching it on. My ultimate goal is to have one "Parameter Criteria Form" to serve any of the reports I want to use therefore putting in a code with a report's name will only allow that form to be use for that report. Am I correct in this thinking? How can I apply the form to multiple reports?

    Private Sub CmdFilter_Click()
    Dim strBldgNum As String
    Dim strFSL As String
    Dim strCommander As String
    Dim strInspector As String
    Dim strDistrict As String
    Dim strFY As String
    Dim strState As String
    Dim strCity As String
    Dim strFilter As String


    If IsNull(Me.BldgNumCmb.Value) Then
    strBldgNum = "Like '*'"
    Else
    strBldgNum = "='" & Me.BldgNumCmb.Value & "'"
    End If
    If IsNull(Me.FSLCmb.Value) Then
    strFSL = "Like '*'"
    Else
    strFSL = "='" & Me.FSLCmb.Value & "'"
    End If
    If IsNull(Me.CommanderCmb.Value) Then
    strCommander = "Like '*'"
    Else
    strCommander = "='" & Me.CommanderCmb.Value & "'"
    End If
    If IsNull(Me.InspectorCmb.Value) Then
    strInspector = "Like '*'"
    Else
    strInspector = "='" & Me.InspectorCmb.Value & "'"
    End If
    If IsNull(Me.DistrictCmb.Value) Then
    strDistrict = "Like '*'"
    Else
    strDistrict = "='" & Me.DistrictCmb.Value & "'"
    End If
    If IsNull(Me.FYCmb.Value) Then
    strFY = "Like '*'"
    Else
    strFY = "='" & Me.FYCmb.Value & "'"
    End If
    If IsNull(Me.StateCmb.Value) Then
    strState = "Like '*'"
    Else
    strState = "='" & Me.StateCmb.Value & "'"
    End If
    If IsNull(Me.CityCmb.Value) Then
    strCity = "Like '*'"
    Else
    strCity = "='" & Me.CityCmb.Value & "'"
    End If
    strFilter = "[BldgNum] " & strBldgNum & " AND [FSL] " & strFSL & " AND [Commander] " & strCommander & " AND [Inspector] " & strInspector & " AND [District] " & strDistrict & " AND [FY] " & strFY & " AND [State] " & strState & " AND [City] " & strCity

    On Error GoTo Err_CmdFilter_Click

    Screen.PreviousControl.SetFocus
    DoCmd.FindNext
    Exit_CmdFilter_Click:
    Exit Sub
    Err_CmdFilter_Click:
    MsgBox Err.Description
    Resume Exit_CmdFilter_Click

    End Sub

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

Similar Threads

  1. Unmatched query with multiple criteria
    By brighteyes in forum Access
    Replies: 0
    Last Post: 10-26-2011, 06:37 AM
  2. Multiple criteria query
    By jwb257 in forum Queries
    Replies: 6
    Last Post: 10-21-2011, 02:29 PM
  3. Query criteria, multiple tables
    By Vicker in forum Queries
    Replies: 2
    Last Post: 08-16-2011, 01:44 AM
  4. Replies: 1
    Last Post: 07-13-2011, 11:00 AM
  5. Multiple criteria query
    By DJ-Specter in forum Queries
    Replies: 1
    Last Post: 09-23-2009, 04:47 AM

Tags for this Thread

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