Dynamic Report-Caption

E

Elisabeth Reuter

Hello,

I have a problem with the Report-Caption: I want to change the caption
(title) of the report when I print it using docmd.openreport with
acviewnormal in vb.

When I open a preview with the acviewpreview-option I can change the caption
of the report eg. with report.caption=me!title.

When calling the report with acviewnormal this does not work and the name of
the title-field is ignored and in the job-queue of the printer the static
caption of the report is shown.

Is it possible to change the caption dynamically without first calling a
preview.

greetings from Austria
 
M

Marshall Barton

Elisabeth said:
I have a problem with the Report-Caption: I want to change the caption
(title) of the report when I print it using docmd.openreport with
acviewnormal in vb.

When I open a preview with the acviewpreview-option I can change the caption
of the report eg. with report.caption=me!title.

When calling the report with acviewnormal this does not work and the name of
the title-field is ignored and in the job-queue of the printer the static
caption of the report is shown.

Is it possible to change the caption dynamically without first calling a
preview.


Trying to set any property of a report from outside the
report is not a reliable approach in any situation. The
difficulty is that report processing is asynchronous from
the code that called the OpenReport method so you no control
over the state of the report.

The reliable way to do this kind of thing is to use code in
the report (in this case the Open event) to "pull" the title
from the form instead of trying to get the form to "push"
the title into the report.

I think the line of code in the report's Open event would
look like:
Me.caption = Forms!the formname.title
 
E

Elisabeth Reuter

Trying to set any property of a report from outside the
report is not a reliable approach in any situation. The
difficulty is that report processing is asynchronous from
the code that called the OpenReport method so you no control
over the state of the report.

The reliable way to do this kind of thing is to use code in
the report (in this case the Open event) to "pull" the title
from the form instead of trying to get the form to "push"
the title into the report.

I think the line of code in the report's Open event would
look like:
Me.caption = Forms!the formname.title

I tried this, but it does not work. It seems to be too late when the report
opens. The name of the report has then already been sent to the printer and
in the printer-queue the static report-caption is listed.

I fear, this problem cannot be solved without opening a preview before
printing.

Greetings


Elisabeth
 
M

Marshall Barton

Elisabeth said:
I tried this, but it does not work. It seems to be too late when the report
opens. The name of the report has then already been sent to the printer and
in the printer-queue the static report-caption is listed.

I fear, this problem cannot be solved without opening a preview before
printing.


This should not be a problem if you're using the OpenReport
method to open the report and the form doesn't close itself
right after starting the report. Maybe you're using
something else??? OTOH, maybe you should just be setting
the Caption of a label on the report, instead of setting the
report object's Caption. (I have never seen the report's
Caption appear in a printed report so I'm not sure we're
talking about the same thing here.)

Post the code that opens the report and the code in the
report's Open event and maybe someone will spot something.
 
E

Elisabeth Reuter

This should not be a problem if you're using the OpenReport
method to open the report and the form doesn't close itself
right after starting the report. Maybe you're using
something else??? OTOH, maybe you should just be setting
the Caption of a label on the report, instead of setting the
report object's Caption. (I have never seen the report's
Caption appear in a printed report so I'm not sure we're
talking about the same thing here.)

Post the code that opens the report and the code in the
report's Open event and maybe someone will spot something.


Here is the code in the form:

DoCmd.OpenReport "R_Invoice", acViewNormal, , "Inv_ID = " & [Invoice_ID]


In the Open event of the Report I write eg.

Me.Caption = "test"

This "test" should then be displayed in the printer-queue but there the
original caption is listed.



But: when I write in the form

DoCmd.OpenReport "R_Invoice", acViewPreview, , "Inv_ID = " & [Invoice_ID]

and then print it the "test" is displayed in the printer-queue (and in the
title of the Report).

To me it seems that the printer gets the report-caption just before the
open-event of the report and the Me.Caption (or Me.Report.Caption) cannot
change this name.

Greetings and thanks form Austria

Elisabeth
 
M

Marshall Barton

Elisabeth said:
This should not be a problem if you're using the OpenReport
method to open the report and the form doesn't close itself
right after starting the report. Maybe you're using
something else??? OTOH, maybe you should just be setting
the Caption of a label on the report, instead of setting the
report object's Caption. (I have never seen the report's
Caption appear in a printed report so I'm not sure we're
talking about the same thing here.)

Post the code that opens the report and the code in the
report's Open event and maybe someone will spot something.

Here is the code in the form:

DoCmd.OpenReport "R_Invoice", acViewNormal, , "Inv_ID = " & [Invoice_ID]

In the Open event of the Report I write eg.

Me.Caption = "test"

This "test" should then be displayed in the printer-queue but there the
original caption is listed.

But: when I write in the form

DoCmd.OpenReport "R_Invoice", acViewPreview, , "Inv_ID = " & [Invoice_ID]

and then print it the "test" is displayed in the printer-queue (and in the
title of the Report).

To me it seems that the printer gets the report-caption just before the
open-event of the report and the Me.Caption (or Me.Report.Caption) cannot
change this name.


I hadn't realized the it was the display in the printer
queue that you are trying to affect.

In that situation, it certainly appears that your conclusion
is correct. I won't even try to figure out why the printer
gets involved before the open event completes.

There may be some tricks you can use to delay the printer's
involvement short of using preview, but I don't know what
those tricks might be. (Stab in the dark: assign the
report's record source last thing in the open event?)

Maybe someone else will have an idea if you repost this
message to a new thread?

Good luck,
 

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