Link to home
Start Free TrialLog in
Avatar of Painfree888
Painfree888

asked on

Referencing DoCmd.OpenReport openargs


Hello all,

Have what is probably a really easy question, though I can't seem to figure it out. Background: I have a report that is based on a form. Er, I should probably explain that in more detail. I have two forms, named FormA and FormB. On this form, I have a button, labeled "Print Screen Report". When a user clicks this button, a report opens that is basically the form in report format (do this because users will often want to print out the form, and reports are just more printer friendly). FormA and FormB are very similar, in that they contain many of the same fields (though functionally, they are very different). When I first created my little app, I created two Print Screen reports, one each for FormA and FormB (the report names are PS_FormA and PS_FormB).

Well, it seems stupid now to have to print screen reports. What I would like to do is to have one print screen report. The way I reference the form fields on the Print Screen reports is in the control source of the report field is something like this:

Forms!FormA!FieldA

This will show the data in field A of FormA in the report field (the print screen reports may only be opened when a user is in the form, so no chance of running into an #error).

Now, as I said, just want one print screen report to work with both forms. My thought is that I should use the openargs in the DoCmd.OpenReport command. In the args, I would like to pass the form name of the calling form. then use the form name passed to the report to set the field reference in the report fields. I imagine it would look something like this:

Field control source: =Forms(formName)!FieldA

Where formName is the name of the form passed in the openargs portion of the DoCmd.OpenReport command.

My question is this: what is the proper way to do this? I've tried it a couple of different ways, but can never seem to reference the arguments I am passing to the report.

Hopefully this all makes sense. Let me know if you need more info or if something here is unclear.

Thanks!
ASKER CERTIFIED SOLUTION
Avatar of Scott McDaniel (EE MVE )
Scott McDaniel (EE MVE )
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
Avatar of Painfree888
Painfree888

ASKER


OK, think understand what you are saying. Understood about basing the report on a query, but here's the info I left out:

*FormA and FormB are unbound forms. They are saved by clicking a save button.
*Users want to be able to fill out the form and print it out, sometimes before saving. Their request, so I gave them what they wanted. Printing forms is sometimes dicey, and ugly. So, created the print report to give them a printer friendly version of the report. Can't really base these reports on a query.

I like the way you have suggested I approach this. I do not, presently, have the controls on my report named, but that will change when I implement this. Excellent advice.

BTW, I believe that the code will have to go into the Activate event handler, as this appears to be the only place you may set or change report values (at least, I know it may not be done in the Open event).

Let me try this out and I'll get back to you. As always, thanks for the help, LSM.

Arek

LSM, that did it, thanks for the help!