Cant get a report to print

R

Robbo

In a couple of my routines I display a list of errors using a simple msgbox.
Some users want to be able to print that so I want to use the following code
to print it off.
iPrint = MsgBox(sMessage & vbNewLine & vbNewLine & "Do you want to print
this message?", vbYesNo, "Print")
if iPrint = vbYes then DoCmd.OpenReport "rptSysMessage", , , , , PrintMessage

rptSysMessage is an unbound report that contains a single unbound variable
called PrintMessage and I have loaded the following code in the On
Report_Load event: Me.PrintMessage = Me.OpenArgs

I have also tried moving the code into the On_Activate Event too.

Try as I will I can't seem to get the OpenArgs value to get to the report so
all I get is a blank page. Can anyone tell me what I am doing wrong?
 
R

RoyVidar

Robbo said:
In a couple of my routines I display a list of errors using a simple
msgbox. Some users want to be able to print that so I want to use
the following code to print it off.
iPrint = MsgBox(sMessage & vbNewLine & vbNewLine & "Do you want to
print this message?", vbYesNo, "Print")
if iPrint = vbYes then DoCmd.OpenReport "rptSysMessage", , , , ,
PrintMessage

rptSysMessage is an unbound report that contains a single unbound
variable called PrintMessage and I have loaded the following code in
the On Report_Load event: Me.PrintMessage = Me.OpenArgs

I have also tried moving the code into the On_Activate Event too.

Try as I will I can't seem to get the OpenArgs value to get to the
report so all I get is a blank page. Can anyone tell me what I am
doing wrong?

Try assigning the value in the on format event of the section in
which the control resides.

I e, if you've placed the control in the detail section, use the
detail section's on format event.
 
D

Douglas J. Steele

If I'm understanding you correctly, the message you want printed on the
report is contained in sMessage. That means your OpenReport statement should
probably be

if iPrint = vbYes then DoCmd.OpenReport "rptSysMessage", , , , , sMessage
 
R

Robbo

Hi Roy,

I tried your suggestion but it made no difference. I stepped through the
code and your code did not even get exectuted. The problem when I step
through the code is that the OpenArgs value isn't being received by the form.
When I hover over Openargs is says Openargs = NULL, yet when I hover over the
Openargs value in the DoCmd.OpenReport command it clearly contains the message
 
R

Robbo

Hi Douglas, sorry to confuse. There is a slight difference in the formatting
of the two messages. PrintMessage definitely has a value when I issue it but
for some reason the OpenArgs value is not being delivered to the Report
 
R

RoyVidar

Robbo said:
Hi Roy,

I tried your suggestion but it made no difference. I stepped through
the code and your code did not even get exectuted. The problem when
I step through the code is that the OpenArgs value isn't being
received by the form. When I hover over Openargs is says Openargs =
NULL, yet when I hover over the Openargs value in the
DoCmd.OpenReport command it clearly contains the message --
Cheers
Rob

Just shows I'm more used to using acViewPreview, and not sending
directly to the printer.

It seems some of the on format events either doesn't work, or doesn't
perform all code, for some reason, when acViewNormal (the default) is
used. Take it with a grain of salt, but found out through some testing
and web search.

It might, or will, work if you try using the On Format event of the
Report Haeder section

If not, I'd consider a one field table to use as recordsocurce, and
just update the field with the message prior to running the report.
 
D

Douglas J. Steele

See whether using a named parameter makes a difference:

DoCmd.OpenReport "rptSysMessage", OpenArgs := PrintMessage
 
R

Robbo

Hi Roy,

I tried all sorts of alternatives but your idea of putting the value into a
table and printing from there was the only one that worked.
 
R

Robbo

Hi Douglas,
Nothing seemed to work. The parameter value just doesn't seem to come in
when I try to print direct to the printer - it works fine when I do a
preview. The only way I could get it to work was to put the value into a
table and print from there.

Thanks for your suggestions
 
R

RoyVidar

Robbo said:
Hi Roy,

I tried all sorts of alternatives but your idea of putting the value
into a table and printing from there was the only one that worked.


Glad you got it working :)

I managed to get it working with the Report Header on format event,
though the important thing is that it works as expected :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top