Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

running a report from a form based on the result of a query

Status
Not open for further replies.

farquar

Programmer
Nov 21, 2001
14
GB
I have been looking at questions raised before and I now know how to determine whether a query has any records, i.e. recordcount. I have a form where you enter a location. I have a report which is based on a query. The query selects from a table where the location in the table matches the location that the user has entered in the form. I only want to run the report if the query returns any records. In the form, I want to run the query to see if it returns any records, I have tried to do this and I have tried to use recordcount but I have a problem running the query because in the WHERE clause it references [Forms]![formname].[location]. The following message appears: 'Too few parameters. Expected 1'
 
Try This:
Set the report's recordsource to the query name
In the No_Data event of the report enter "Cancel = True"
On your form, create a command button with the following code in the Click event:
DoCmd.OpenReport "Your Report Name", acViewNormal
This ought to have the effect of opening the report, but if there is no data returned by the query to the report, it will simply close without displaying. Worth a try?....
-Geno
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top