Link to home
Start Free TrialLog in
Avatar of Scamquist
ScamquistFlag for United States of America

asked on

Run Access 2007 report based on query using a dialog box to supply the criteria

I have a report COMMUNICATION BY LOCATION that uses the query CommLine, which is based on the dialog box SelComTypeLoc.  
The criteria for the query is [Forms]![SelComTypeLoc]![cLoc]

When I open the dialog box   SelComTypeLoc and enter my value (cLoc) into a drop down box, the query executed properly.

I am trying to open the report and run it based on the values set in the dialog box SelComTypeLoc to run the query CommLine.

The report record source cannot be the form  SelComTypeLoc.  

How can I have the report run the dialog box to select the query values?
Avatar of symsoft
symsoft

Are you sure you want to open the form from the report, or open the report from the form?

I would change the Recordsource property of the form during the Open event using VBA code.  Something like:

Report.Recordsource = "SELECT * FROM MyTable WHERE Criteria = ' & Forms]![SelComTypeLoc]![cLoc].

I'm sure you'll need to tweak that a little...
Avatar of Scamquist

ASKER

If I remove the paramaters from the query, the report will run with CommLine as the record source in the report.  I know the dialog box works because if I open the form SelComTypeLoc first, enter my value and click OK the proper value is returned on the query.  I am trying to open the report and run the query based on the dialog box in one smooth step.  

One other piece,  I am using a command button on another form to kick off the report...if that makes any difference.
ASKER CERTIFIED SOLUTION
Avatar of Jeffrey Coachman
Jeffrey Coachman
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
OUTSTANDING!
Thank you for your help,  The attached file saved the day.  I found the link you provided, which is how I got as far as I did.  However, the code they use is to have the OK button run the query, not open the report.  The OK button on my dialog box was opening the query, not the report.  I made the change and it worked like a champ.     Thank you again.again.