parameratized report

  • Thread starter Thread starter Christopher Glaeser
  • Start date Start date
C

Christopher Glaeser

How do I parameratize a report so that it can be opened from command buttons
on various forms? I think the code is something like:

DoCmd.OpenReport "rptMyReport", acPreview
Report!rptMyReport!<what_goes_here1> = Me.CallerName
Report!rptMyReport!<what_goes_here2> = Me.CallerCompany
Report!rptMyReport!<what_goes_here3> = Me.CallerPhone

I've done this type of thing for a form, but the form had a record source,
and each <what_goes_here> was a text box bound to a table entry. Can this
be done for a report without a record source? Or, is there a better
approach? I tried setting the Captions of unbound Text Labels, and that did
not seem to work.

Best,
Christopher
 
The way I do it!
Put the button on the form- then report operation- preview report- then
select the report.

Hope that helps,
 
Put the button on the form- then report operation- preview report- then
select the report.

Many thanks Dave, I've got that far. The part I'm struggling with is the
code in the command button click event. What type of object should I place
on the report (e.g. text label or text box) that can be change
programatically, and what is the line of code to do this? I'm guessing it's
something like:

Reports!MyReport!some_sort_of_object = Me.CallerName

then, from another command button on another form, I could use

Reports!MyReport!some_sort_of_object = Me.CustomerName

Does the object need to be bound to a table or query? Or, can I
programatically set unbound objects?

Best,
Christopher
 
Christopher,

I am pretty sure you can't do it like this... at least I would never try
it this way around. I'm pretty sure that by the time the report is
opened, it's too late to start trying to manipulate what's on it.
Therefore the code has to be run from the report, not from the form. If
there is code, that is. In your case, if I understand you correctly,
there is no need for code. Just put unbound textboxes on the report,
with their Control Source set for example like this...
=[Forms]![NameOfYourForm]![CallerName]
 
Just put unbound textboxes on the report, with their Control Source set
for example like this...
=[Forms]![NameOfYourForm]![CallerName]

Thanks, this is helpful. For now, I am using multiple versions of the
report, which can be called from various forms, as in ...

Button on frmMessages uses:
=[Forms]![frmMessages]![CallerName]

Button on frmWorkOrder uses:
=[Forms]![frmWorkOrders]![CustomerName]

.... and so on.

These reports print a Dymo label, and it can be invoked from six or eight
different forms, so I now I have six or eight reports, one for each command
button. If I want to change a feature like font, I must update all eight
reports. That's why I was searching for an approach to parameratize a
report, so that I could have one report invoked from many different forms.

Best,
Christopher
 
Christopher,

Ah, the plot thickens! I am not quite clear on what you mean by
referring to the buttons on the forms. But there would be easier ways
around this than having a separate report to correspond with each
calling form.

Which version of Access are you using? In Access 2003, and also 2002 I
thnk, the OpenReport method provides an OpenArgs argument that you could
then use on the report's Open event to set the Control Source property
of the report controls. So, as an example, the button on each form can
do something like this....
DoCmd.OpenReport "Dymo", acViewPreview, , , , Me.Name

.... and the Open event of the report can do something like this...
Select Case Me.OpenArgs
Case "frmMessages"
Me.MyTextbox.ControlSource = "=Forms!frmMessages!CallerName"
Case frmWorkOrder
Me.MyTextbox.ControlSource = "=Forms!frmMessages!CustomerName"
- etc -
End Select

I haven't tested this, but I think it will work. As I said, I am still
a bit confused about what you are doing, so just adapt the general concept.
 
Thanks Steve, this is what I was trying to ask.
Ah, the plot thickens! I am not quite clear on what you mean by referring
to the buttons on the forms.

frmContacts, frmWorkOrders, etc, each have command buttons that will print a
label, accessing the relevant fields from each form. I've already
implemented a set of buttons for printing faxes from each of these forms,
but the fax report is based on tblFaxLog and frmFaxLog, so the
implementation was different. In the case of printing the labels, I want to
do more or less the same thing, but there is not a log of printed labels,
just the rptDymoLabel.

.... good stuff deleted ...
I haven't tested this, but I think it will work. As I said, I am still a
bit confused about what you are doing, so just adapt the general concept.

I think you nailed it. Thanks!!!

Best,
Christopher
 
Back
Top