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.

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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.

Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.