Results 1 to 5 of 5
  1. #1
    rhubarb is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Sep 2011
    Posts
    76

    Report Filtering

    Currently I have a form that allows the user to enter a date range and it will return a ticket report based on that range once the preview button is pushed. If the date range is blank it returns all possible tickets from the report. This works.

    I would like to add functionality to this filtering so I added a list box with other options such as address, employee, ticket, etc. Below that I added a combo box that, based on list box selection, displays further detail. (If address is selected then the combo box displays all possible addresses).

    I have one report that lists all possible information and I would like to reuse this for all variations of reports if possible.

    If I can get the basic filtering working I would like to have the capability to filter by date and an item in the list box, ie. an employee between the inputted date range.



    Any help is appreciated.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,626
    Either have the report RecordSource refer to the report controls for input parameters or pass filter criteria to the report through code (macro or VBA) when the report opens.

    In an event, such as button Click, execute a macro or VBA with command to open report with criteria. In VBA would look like:
    DoCmd.OpenReport "report name", , , "fieldname1=" & Me.textbox1 & " AND fieldname2='" & Me.textbox2 & "' AND fieldname3=#" & Me.textbox3 & "#"

    Example shows use of delimiters: apostrophe for text, # for dates
    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.

  3. #3
    rhubarb is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Sep 2011
    Posts
    76
    Thanks for the reply. This is steering me in the right direction.

    So far I am leaving the date range alone and just trying to open up reports based on my list and combo box.

    I have:
    lstTicketReport = ListBox
    This has six static filtering fields (Billable, Employee, Ticket, etc)

    lstTicketFilter = ComboBox
    This opens up possible values from the above selection. (If Employee is selected the combo box shows all possible employees)

    I am a complete beginner when it comes to code so I'm sure it could be more efficient.

    Private Sub cmdPreview_Click()


    If Me.lstTicketReport.Selected(0) = True Then
    DoCmd.OpenReport "All Tickets Billable", acViewPreview

    ElseIf Me.lstTicketReport.Selected(3) = True Then
    DoCmd.OpenReport "All Tickets Non-Billable", acViewPreview

    ElseIf Me.lstTicketReport.Selected(5) = True Then

    End If

    End Sub


    Now first I think it's ridiculous to statically address the items in the list box. It's only possible here because I only have 6 items to filter the reports by. I think a loop would be better but I'm not sure how to code it.

    Which leads to how do I code the combo box? I've selected (5) above which happens to be tickets so the combo box drops down with all possible tickets. How can I track the tickets so when I click preview it brings up the right one selected. This is where I thought the loop would be necessary because there could be hundreds of tickets. So perhaps it would be a loop within a loop?

    Thanks!

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,626
    Going by the code example you show, this might be possible:

    DoCmd.OpenReport "All Tickets " & Me.lstTicketReport, acViewPreview

    But this will show all tickets. If you want to filter to specific criteria (employeeID, ticketID, etc), don't open report from the listbox event. Use it to requery the combobox. The combobox AfterUpdate event would then open the report.

    DoCmd.OpenReport "All Tickets " & Me.lstTicketReport, acViewPreview, , filter criteria string here

    Constructing the filter criteria string is the trick. If you include another criteria, such as date range, that will be entered in textboxes, use a button click to execute the OpenReport action.

    This can get quite complicated.

    Check out tutorials here http://www.datapigtechnologies.com/AccessMain.htm

    Especially:
    the 3 about comboboxes under Access Forms:Control Basics
    and
    Build a Custom Filter in Your Form under Access Forms:Tips and Techniques
    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.

  5. #5
    rhubarb is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Sep 2011
    Posts
    76
    Okay so from that tutorial I was able to see how to add the criteria in the record source of report that points to my lstTicketFilter. Great tutorials!

    Thanks so much for the help!

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

Similar Threads

  1. Filtering a report
    By tarhim47 in forum Reports
    Replies: 2
    Last Post: 03-30-2011, 11:49 AM
  2. Report filtering
    By banjo1t in forum Reports
    Replies: 4
    Last Post: 01-26-2011, 06:43 AM
  3. Report Filtering..
    By banjo1t in forum Reports
    Replies: 1
    Last Post: 01-24-2011, 06:56 AM
  4. Filtering in a report
    By SIM_2009 in forum Reports
    Replies: 1
    Last Post: 10-06-2009, 04:22 AM
  5. Filtering my report
    By ldarley in forum Reports
    Replies: 1
    Last Post: 09-05-2008, 09:14 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