Formatting header of sub report from code (1 Viewer)

petko

Registered User.
Local time
Today, 11:12
Joined
Jun 9, 2007
Messages
85
Hi There,

I have a report with a sub report for making invoice. Column header on sub report are label and their caption should be visible or invisible, bolded or not bolded, depending on what language is set for the invoice.
I'd like to set these parameters - after opening the report - from vba code.

My problem is that the headers look fine, according to the set parameters - but only in report view. In preview it seem my codes are ignored.

Do you have any suggestion?

Thanks in advance

Petko
 

theDBguy

I’m here to help
Staff member
Local time
Today, 03:12
Joined
Oct 29, 2018
Messages
21,357
Hi. For Reports, it all depends on which event you're using. Try using either the Format or Print event, instead of the Open or Load event.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 06:12
Joined
Feb 19, 2002
Messages
42,970
Your code runs in Print Preview and Print but not in report view
 

petko

Registered User.
Local time
Today, 11:12
Joined
Jun 9, 2007
Messages
85
Sorry, I forgot to mention that code is run from the form, the report is opened from. On clicking scenario of the opener button basically like this is that runs:

DoCmd.OpenReport "Invoice", acViewPreview, "InvoiceID = " & Me.InvoiceID, acWindowNormal

With Reports!Invoice.InvoiceSubReport.Report

.Header1.FontBold = True
.Header2.Visible = False
... etc

End With

Result works fine if I switch manually to Report View but while I'm in Preview the set parameters are ignored.
I don't run any code on the Report's scenario

Do you have any idea?

Thanks again!

petko
 

theDBguy

I’m here to help
Staff member
Local time
Today, 03:12
Joined
Oct 29, 2018
Messages
21,357
Sorry, I forgot to mention that code is run from the form, the report is opened from. On clicking scenario of the opener button basically like this is that runs:

DoCmd.OpenReport "Invoice", acViewPreview, "InvoiceID = " & Me.InvoiceID, acWindowNormal

With Reports!Invoice.InvoiceSubReport.Report

.Header1.FontBold = True
.Header2.Visible = False
... etc

End With

Result works fine if I switch manually to Report View but while I'm in Preview the set parameters are ignored.
I don't run any code on the Report's scenario

Do you have any idea?

Thanks again!

petko
Once a report is rendered, some parts can no longer be changed. It's better to use report events for those cases.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 06:12
Joined
Feb 19, 2002
Messages
42,970
The code to modify the format of the report, belongs in the report's events. Probably the Format events of the various sections.
 

Users who are viewing this thread

Top Bottom