Open Report with selective criteria

  • Thread starter Thread starter rzwlkr33
  • Start date Start date
R

rzwlkr33

I have a database and i want to create a report where I can choose from a
list of names from a dropdown menu and when I choose the list of names it
will go the report for just that name which I choose. I dont know if I
should do this as an event property or a code? How would I go about doing
this?
 
I have a database and i want to create a report where I can choose from a
list of names from a dropdown menu and when I choose the list of names it
will go the report for just that name which I choose. I dont know if I
should do this as an event property or a code? How would I go about doing
this?

You'll need to use a form to do this.

First, create a query that will display the fields you wish to show in
the report.

Second, create a report, using the query as it's record source, that
shows the data you wish to display for ALL records.

Let's assume it is a CustomerID number you need as criteria.

Next, make a new unbound form.
Add a combo box that will show the CustomerID field as well as the
Customer Name field (you can use the Combo Box wizard to do so).
Set the Combo box's Column Count property to 2.
Hide the CustomerID field by setting the Combo box's ColumnWidth
property to 0";1"
Make sure the Combo Box Bound Column is the
CustomerID field.
Name this Combo Box "cboFindName".

Add a command button to the form.
Code the button's Click event:
Me.Visible = False
Name this form "ParamForm"

Go back to the query. As criteria, on the Query's CustomerID field
criteria line write:
forms!ParamForm!cboFindName

Code the Report's Open Event:
DoCmd.OpenForm "ParamForm" , , , , , acDialog

Code the Report's Close event:
DoCmd.Close acForm, "ParamForm"

Run the Report.
The report will open the form.

Find the CustomerName in the combo box.
Click the command button.

The Report will display just those records selected.
When the Report closes it will close the form.
 
There's a parameter of the openreport function called WhereCondition, it will
allow you to filter what data you want to show.

DoCmd.OpenReport stDocName, acPreview, ,"Some_Field = <Some Value>"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top