• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 275
  • Last Modified:

How to populate report based on criteria specified in form?

Hello Experts,

I have noticed several references to this subject but I’m having trouble creating a solution that meets my needs.

My goal is to have a form that allows the user to select the criteria used to filter an existing query and populate the report based on the results of that query.

In Access 2000 I have a query called “qryReport”. This query contains several expressions that generate a master record set of all the data I need for my reports.

The report is called “rptReport”.  It contains selected fields found in qryReport. These fields will not change on the report (at least for now).

Finally, I have a form that contains about 30 text, combo and checkbox objects that will be used to filter data found in qryReport and populate the report. I also have a combobox that allows users to sort data based on the fields represented in the report.

I will also be looking into exporting this report as and Excel spreadsheet. I’m not looking for a solution for this particular feature right now, but I thought I’d mention my future plans in case it impacts the solution.

I have tried sending parameters to qryReport, modifying the record source in rptReport on the fly, and applying filters to rptReport but I keep running into roadblocks.  

I’m looking for a solution that can easily be managed if the criteria on the form must change.

Any suggestions or samples would be greatly appreciated.

  • 4
  • 3
1 Solution
I put this

   Me.Filter = Forms.frmProjectSummary.Filter
   Me.FilterOn = Forms.frmProjectSummary.FilterOn
   Me.OrderBy = Forms.frmProjectSummary.OrderBy
   Me.OrderByOn = Forms.frmProjectSummary.OrderByOn

In my Report OnOpen and it pulls the sort order and filter properties from my Project Summary Form.
JakeB52Author Commented:
Thanks CrossWired.

I should add that the information collected on my form may not exactly reflect the text that I'm filtering. For example, a combobox may have a list of countries, and even though "Germany" may appear as the selected item to the user, I'm actually filtering based on the country's id ( cboCountry.Column(0) ). The data contained in my combobox may look something like this:


whereas the item that appears to the user will depend on the language mode he/she is using.

So overall, I would prefer not to depend on the data that is displayed on the form to filter my report.
On the form you would have to setup the filter correctly, I use 2 ComboBoxes to set the different filter criteria and once my project summary shows the right info, I hit a button and it pulls up the correct report.  If you need an example of my form filtering code let me know.

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

JakeB52Author Commented:
A code sample would be helpful. Thanks.
I have 1 button - Command33
2 Checkboxes - Check75 - which includes or excludes info from Comb73
                    - Check77 - which includes or excludes info from Combo31
2 ComboBoxes - Combo73 - which list different filtering criteria (aka "Current Projects", "Current Quotes")
                      - Combo31 - which list all the engineers names

Private Sub Command33_Click()
If Me.Check75 = True Then
    Select Case Me.Combo73
    Case 1
        tempStage = "(Stage = 9)"
        Me.Label81.Caption = "Current Quotes"
        Me.Label87.Caption = ""
    Case 2
        tempStage = "((Stage > 0) AND (Stage < 9)) AND IsNull(Priority)"
        Me.Label81.Caption = "Current Projects"
        Me.Label87.Caption = ""
    Case 3
        FilterDays = InputBox("How many days back should I show?")
        FilterDate = Format(DateAdd("d", -(FilterDays), Now()), "mm/dd/yyyy")
        tempStage = "(Stage = 0) AND ((DelivDate > #" & FilterDate & "#) AND (DelivDate <> Null))"
        Me.Label81.Caption = "Recently Completed Projects"
        Me.Label87.Caption = "Last " & FilterDays & " Days"
    Case 4
        tempStage = "(Priority = 'H')"
        Me.Label81.Caption = "Projects on Hold"
        Me.Label87.Caption = ""
    Case 5
        StartDate = InputBox("What start date?", , Format(Now(), "mm/dd/yyyy"))
        EndDate = InputBox("What end date?", , Format(Now(), "mm/dd/yyyy"))
        tempStage = "(Stage = 0) AND ((DelivDate > #" & StartDate & "#) AND (DelivDate < #" & EndDate & "#) AND (DelivDate <> Null))"
        Me.Label81.Caption = "Specific Dates Completed Projects"
        Me.Label87.Caption = StartDate & " - " & EndDate
    Case 6
        DoCmd.OpenForm "frmCompanyPopUp", , , , , acDialog
        Comp = Forms("frmCompanyPopUp").Combo0.Value
        tempStage = "CompID = " & Comp
        Me.Label81.Caption = "All Projects for " & DLookup("CompName", "tblCompany", "ID = " & Comp)

    End Select
End If

Me.FilterOn = False
If Me.Check77 = True Then
    Me.Filter = "(PL = " & "'" & Me.Combo31 & "')"
    If Me.Check75 = True Then
        Me.Filter = "(" & Me.Filter & " AND " & tempStage & ")"
    End If
ElseIf Me.Check75 = True Then
    Me.Filter = tempStage
End If

If Me.Check77 = False And Me.Check75 = False Then
Me.Filter = ""
End If

Me.FilterOn = True

End Sub
JakeB52Author Commented:

My apologies for not getting back to your sooner... I came across a few issues while generating my reports that were not directly related to this posting. Your suggestions worked great. Thank you very much!
no problem, it got you going so everyoen is happy

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now