Log in

View Full Version : Solved: Proper syntax for "OpenReport" command



AKK
07-21-2009, 10:20 AM
I'm trying to write a VBA command for opening a report (from a form with controls for calling the macro below once the user has entered the appropriate data) -- I've found a few resources on what the proper syntax is, but it looks like I'm still doing something wrong. Currently:


Option Compare Database
Private Sub cmdCancel_Click()
DoCmd.Close acForm, "LookupCharterSummaryTEST"
End Sub
Private Sub cmdOK_Click()
DoCmd.OpenReport "Charter Summary TEST", acViewPreview, "Charter Summary"
DoCmd.Close acForm, "LookupCharterSummaryTEST"
End Sub


I'm not sure if I'm entering the filter argument correctly ("Charter Summary" is the name of the query that the report "LookupCharterSummaryTEST" is built on), and I'm unclear on what to enter for the WindowsMode & OpenArgs arguments.

This is all pretty new to me, so if you could be as specific about the syntax as possible, I would really appreciate it (ie, don't assume I know where to use commas, brackets, quotation marks, etc). Thanks so much!

OBP
07-22-2009, 02:58 AM
You do not need to specify the query that the report is using for it's Record Source so you should remove the comma and "Charter Summary" from the docmd line so you just have
DoCmd.OpenReport "Charter Summary TEST", acViewPreview

The Filter is for "Restricting" the records in the Report.

AKK
07-22-2009, 08:28 AM
Sigh...thanks for trying, but nope. Same problem, same error.

OBP
07-22-2009, 08:52 AM
What is the error message?

AKK
07-22-2009, 09:10 AM
Sorry, it's not actually an error message, just a problem that keeps happening. After I choose an option from the combo box & hit okay, I get a dialogue box titled "Enter Parameter Value" where the text is Forms!LookupProject!cmbSSPControl. If I type in the same data I just selected from the combo box, it works fine. But the point is NOT to have to type in the data, and to run the report based on choosing an option from the combo box. So that's the problem I keep running into.

OBP
07-22-2009, 09:16 AM
Ok, that has nothing to do with the Syntax of your Button, more to do with the Query Criteria.
It is normal to use
Forms![LookupProject]![cmbSSPControl]
is that what you have used?
Have you double checked the Form and Combo Box names?
Have you set that as a Query Parameter as well, this can be important with Crosstab queries?
Can you post a zipped copy in Access 2000-2003 format with some dummy data in the tables?

AKK
07-22-2009, 10:43 AM
Oops, never mind. I had my query set up wrong. All is well.

Thanks! :)