View Full Version : Report based on Query


mugman17
10-31-2001, 12:20 PM
I have a report that is generated from a query. Basically, you enter the company name on a form and it creates a report that gives the totals for the month. What I would like to do is, if the Supplier Name is not selected, it will generate the reports for all the suppliers.

jwindon
10-31-2001, 02:06 PM
Think the wires are a little crossed. First you said "company name" and then "supplier".

So I'm taking a guess that you meant the same thing for both. In which I case I would answer..

You could also run some code on your event to change the recordsource of the report based on the value of the choice control.

stevebehnke
10-31-2001, 02:07 PM
I would copy the query and delete the criteria that makes you select a company name you will also need a new report based on th copied query this should give a report for all companies.

mugman17
10-31-2001, 02:30 PM
I know I need to add some code, but I cannot get anything to work properly.

jwindon
10-31-2001, 02:55 PM
Put this code on the event that runs your report.

If IsNull(Me.ChoiceControlName) Then
DoCmd.OpenReport "ReportName", acViewPreview
Exit Sub

Else

DoCmd.OpenReport "ReportName", acViewPreview, , "[ControlNameOnReport] = " & Me.ChoiceControlName


End If


PS. You can change the recordsource of your report to the table that you were using in your query now. With this code, the report is queried.


[This message has been edited by jwindon (edited 10-31-2001).]