textbox.visible = false Not Working in Report (1 Viewer)

TheSearcher

Registered User.
Local time
Today, 00:45
Joined
Jul 21, 2011
Messages
304
I have the following code in the On Print event of my report footer:
Code:
Private Sub PageFooterSection_Print(Cancel As Integer, PrintCount As Integer)

If Me.Page = 1 Then
     MsgBox Me.Page
     Me.[lbl_ClientName_Footer].Visible = False
     Me.[txt_ClientName_Footer].Visible = False
Else
     Me.[lbl_ClientName_Footer].Visible = True
     Me.[txt_ClientName_Footer].Visible = True
End If

End Sub

The msgbox tells me that I'm on page 1 - but the controls are still visible (on a 1 page report). However, on a 2 page report it works correctly.
Any ideas why this would be happening?

Thanks in advance,
TS
 

CJ_London

Super Moderator
Staff member
Local time
Today, 05:45
Joined
Feb 19, 2013
Messages
16,607
you can also simplify your code

Code:
Private Sub PageFooterSection_Print(Cancel As Integer, PrintCount As Integer)

     Me.[lbl_ClientName_Footer].Visible = Me.Page <> 1
     Me.[txt_ClientName_Footer].Visible =  Me.Page <> 1


End Sub

not tested but pretty sure if you can associate the label with the textbox, you only need

Me.[txt_ClientName_Footer].Visible = Me.Page <> 1

since hiding the textbox will also hide the associated label
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 00:45
Joined
Feb 19, 2002
Messages
43,263
You're welcome:) You should also look up the Retreat event as well. I don't think it will have any impact on this particular requirement, but it is very important to understand the rendering process for a report. To summarize, Access formats a section before it knows if it has room on the page to actually print it. If there is no room, it runs the retreat event. Then goes through the pagination process to create the footer for the current page and the headers for the next page and then it goes back to the Format event again.

If you are not doing arithmetic, you probably don't care if an event runs multiple times but if you are creating your own custom page numbers or trying to create a page total, you care very much how many times an event runs since you don't want to add the amount you are trying to sum more than once. The FormatCount property of the Format event tells you whether this is the first, second, third, etc time the event runs. And the Retreat event gives you the place to reverse your calculation. Usually, only twice would be necessary but in complex situations, Access may have trouble if the section is more than one line tall so it has to juggle things to get everything to fit. Between the two events, you can figure out how to make the best use of the two events.
 
Last edited:

TheSearcher

Registered User.
Local time
Today, 00:45
Joined
Jul 21, 2011
Messages
304
Thanks Pat! Much appreciated! I will study these events!
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 05:45
Joined
Sep 12, 2006
Messages
15,652
As @Pat Hartman says, reports can be funny things. If you preview a report and then print it, that can also change page counts as they might not be reset for the print process, depending how you actually manage the page counts.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 00:45
Joined
Feb 19, 2002
Messages
43,263
Right. If you preview first, the entire report runs a second time if you print from the preview. If you have custom pagination and page break summaries, it is best to give user the option to print directly to avoid any issues. However, if you use report view to preview the report, none of the page logic runs so that should be safe but you won't see page footers in the preview.
 

Users who are viewing this thread

Top Bottom