Results 1 to 8 of 8
  1. #1
    George is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Feb 2012
    Posts
    295

    Report Filter Problem

    Good Night,



    I have a report called "ExamTimeTablebydate" which I am trying to make dynamic by creating a form with 2 combo boxes that will supply the criteria that changes the form. The combo boxes are "cboOffice" and "cboDepartment". There is a button called "cmdApplyFilter" that triggers the query on the form.
    The fields in "ExamTimeTablebydate" which are associated with the query are "Class" and "Venue".
    The problem is that when values are placed in the combo box and the "cmdApplyFilter" button is press, the report comes up empty, but when the combo boxes are emptied the table is once again fully loaded with values.

    Is there a plausible explanation for this?

    Here is my code:

    Option Compare Database
    Private Sub Form_Load()
    DoCmd.OpenReport "ExamTimeTablebydate", acViewPreview
    End Sub

    Private Sub cmdApplyFilter_Click()
    Dim strOffice As String
    Dim strDepartment As String
    Dim strFilter As String


    ' Check that the report is open
    If SysCmd(acSysCmdGetObjectState, acReport, "ExamTimeTablebydate") <> acObjStateOpen Then
    MsgBox "You must open the report first."
    Exit Sub
    End If
    ' Build criteria string for Office field
    If IsNull(Me.cboOffice.Value) Then
    strOffice = "Like '*'"
    Else
    strOffice = "='" & Me.cboOffice & "'"
    End If
    ' Build criteria string for Department field
    If IsNull(Me.cboDepartment.Value) Then
    strDepartment = "Like '*'"
    Else
    strDepartment = "='" & Me.cboDepartment & "'"
    End If
    ' Combine criteria strings into a WHERE clause for the filter
    strFilter = "[Class] " & strOffice & " AND [Venue] " & strDepartment
    ' Apply the filter and switch it on
    With Reports![ExamTimeTablebydate]
    .Filter = strFilter
    .FilterOn = True
    End With

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,643
    Not sure I'd do it that wy, but this would be a tool to check the filter:

    http://www.baldyweb.com/ImmediateWindow.htm
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,648
    I would build the filter string then open the report using WHERE CONDITION argument

    Try:
    Code:
    If Not IsNull(Me.cboOffice) Then
             strFilter = "Office='" & Me.cboOffice & "'"
    End If
    If Not IsNull(Me.cboDepartment) Then
             strFilter = strFilter & IIf(strFilter <>"", " AND ") & "Venue='" & Me.cboDepartment & "'"
    End If
    DoCmd.OpenReport "ExamTimeTablebydate", acViewPreview, , strFilter
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  4. #4
    George is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Feb 2012
    Posts
    295
    Thank you.

    The code was copy and pasted but, it result in a popup dialog box requesting a value be entered for the 'office'. No request was required for the 'Venue'. So it seems like the string is not passed to the query.

    If no value is entered in the parameter box, no results are returned.

  5. #5
    George is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Feb 2012
    Posts
    295
    If Not IsNull(Me.cboDepartment) Then
    strFilter = strFilter & IIf(strFilter <>"", " AND ") & "Venue='" & Me.cboDepartment & "'"
    End If
    DoCmd.OpenReport "ExamTimeTablebydate", acViewPreview, , strFilter
    [/code][/QUOTE]

  6. #6
    George is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Feb 2012
    Posts
    295
    Thanks. My problem is solved. Your method was so simple to compare with what I started with.

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,648
    Sorry, your field name is Class, not Office. My bad.

    If you want results if nothing entered, then use the LIKE operator structure and no need for the conditionals.

    DoCmd.OpenReport "ExamTimeTablebydate", acViewPreview, , "Class LIKE '" & Me.cboOffice & "*' AND Venue LIKE '" & Me.cboDepartment & "*'"
    Last edited by June7; 05-29-2013 at 01:32 AM.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  8. #8
    George is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Feb 2012
    Posts
    295

    Report filter Problem

    Thanks. I figured it out. I will try the other statements.

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

Similar Threads

  1. filter problem
    By masoud_sedighy in forum Forms
    Replies: 2
    Last Post: 12-15-2011, 01:03 AM
  2. Filter problem
    By Callahan in forum Forms
    Replies: 0
    Last Post: 07-06-2011, 08:03 AM
  3. Filter problem
    By Javad in forum Access
    Replies: 0
    Last Post: 01-22-2011, 01:48 PM
  4. Multiple filter problem.
    By ducecoop in forum Access
    Replies: 2
    Last Post: 10-28-2010, 11:14 AM
  5. Report Filter Problem
    By Imgsolutions in forum Access
    Replies: 2
    Last Post: 07-07-2010, 02:32 PM

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