Hide control on first page of report (1 Viewer)

horseridingjo

New member
Local time
Today, 07:42
Joined
Jul 7, 2010
Messages
8
Hi,
I have created a report that does a running sum of the records per page and it limits the records to 31 per A4 page. The amounts per page is added up and displayed at the bottom of the page in [pgAmounts] the page footer and then carried over to [bfAmounts] the page header of page 2 of the print and so on until the end of the report the page footer has the grand total. It all works fine, totalling up etc but on the first page I keep getting the amount from the first record displayed in the bfAmounts text box whereas it should show no amount as nothing is being carried over.
Is there a simple way to hide the text box [bfAmounts] on page 1 only of the report print? and then its shown on subsequent pages or am I missing an easy way of telling the report that the [bfAmounts] box is 0 balance on page 1?
Does that makes sense?
Thanks
Jo
 

vbaInet

AWF VIP
Local time
Today, 07:42
Joined
Jan 22, 2010
Messages
26,374
You can set the forecolor the first page so it doesn't appear:
Code:
If Me.Page = 1 then
     me.[bfamounts].forecolor = vbwhite
else
     me.[bfamounts].forecolor = vbblack
end if
You can also hide it as well if you want, using me.[bfamounts].visible to True or False depending on the circumstance. Perform this check on the Page Footer's ON FORMAT event.

Welcome to AWF by the way
 

horseridingjo

New member
Local time
Today, 07:42
Joined
Jul 7, 2010
Messages
8
Hi,
Thanks for the welcome and thanks for your reply. I have managed to get it working when in print preview its a treat but for some reason when I print the report off it keeps giving me huge figures instead of the ones that are actually shown in print preview?! Any ideas why?
Here is the VBA code behind it if it helps at all:-
Option Explicit 'Optional, but recommended for every module.
Dim curTotal As Currency 'Variable to sum [Amount] over a Page.
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
Me.PgBrk.Visible = Me.txtCount Mod 31 = 0 ' Sets 31 records to A4 page
End Sub
Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer)
If PrintCount = 1 Then curTotal = curTotal + Me.PaymentAmount
End Sub
Private Sub PageFooterSection_Format(Cancel As Integer, FormatCount As Integer)
Me.PageTotal = curTotal
End Sub
Private Sub PageHeaderSection_Format(Cancel As Integer, FormatCount As Integer)
Me.Text34.Visible = (Me.Page > 1)
'curTotal = 0 'Reset the sum to zero each new Page.
End Sub
 

vbaInet

AWF VIP
Local time
Today, 07:42
Joined
Jan 22, 2010
Messages
26,374
What are you doing here?
Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer)
If PrintCount = 1 Then curTotal = curTotal + Me.PaymentAmount
End Sub

I think you might be over complicating things. Is curTotal a field in the report's record source or it's a calculated field? If it's the former then you can simply use =Sum([curTotal]) + Me.PaymentAmount in a textbox in the Page Footer section of the report.
 

horseridingjo

New member
Local time
Today, 07:42
Joined
Jul 7, 2010
Messages
8
Hi,
No its a calculated field on the report. What I am trying to do is to get each printed page added up and then the amount brought forward and the page amounts to be added in the page footer and displayed and then that amount gets carried over to the bfAmount text box in the page header of the next page.
I have got it working when you view the pages in Print Preview but for some reason when I print it off it is giving me totals of one to two thousand and I cant see where it is getting the amounts from!! Its doing my head in keep looking at it AHHH!!!
Thanks
Jo
 

vbaInet

AWF VIP
Local time
Today, 07:42
Joined
Jan 22, 2010
Messages
26,374
Post a stripped down version of your db so we can have a look.
 

horseridingjo

New member
Local time
Today, 07:42
Joined
Jul 7, 2010
Messages
8
Not sure what you mean.?....! The db is quite large in itself and everything else works fine but basically this report is to print of a small piece of data and calculate each page and carried/bring forward amounts. The data is name, amount and date. I have gave you the VBA code behind the report and I can see it does what its meant to when viewed in Print Preview but when actually printing it off. It is giving completely wrong figures. If I could just use the SUM function in the page header and footer then its not a problem, I think but upon reading the sum function doesnt work in the page header and footers so I have coded it as above but still getting the funny figures on print

VBA code:
Option Explicit 'Optional, but recommended for every module.
Dim curTotal As Currency 'Variable to sum [Amount] over a Page.
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
Me.PgBrk.Visible = Me.txtCount Mod 31 = 0 ' Sets 31 records to A4 page
End Sub
Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer)
If PrintCount = 1 Then curTotal = curTotal + Me.PaymentAmount
End Sub
Private Sub PageFooterSection_Format(Cancel As Integer, FormatCount As Integer)
Me.PageTotal = curTotal
End Sub
Private Sub PageHeaderSection_Format(Cancel As Integer, FormatCount As Integer)
Me.Text34.Visible = (Me.Page > 1) 'Hides brought forward amount on Page 1 of report
'curTotal = 0 'Reset the sum to zero each new Page.
End Sub
Public Function NoData(rpt As Report)
'Purpose: Called by report's NoData event.
'Usage: =NoData([Report])
Dim strCaption As String 'Caption of report.

strCaption = rpt.Caption
If strCaption = vbNullString Then
strCaption = rpt.Name
End If

DoCmd.CancelEvent
MsgBox "There are no records to include in report """ & _
strCaption & """.", vbInformation, "No Data..."
End Function

Name, date and amount text boxes in detail part of report are part of records from db. bfForward text box in page header is unbound that shows amounts from previous page brought forward and gets this from PageTotal unbound box in Page Footer that adds the brought forward amount and the current page amount and displays that total. Thats it but obviously something is not right !
 

horseridingjo

New member
Local time
Today, 07:42
Joined
Jul 7, 2010
Messages
8
Ok to make things simple, does anyone have a simple way to sum an amount column in a text box within the report page footer and then in the next page (page2) have a text box in the page header that carries over the previous total (that is in the page footer of page 1)? Then on page 2 of the footer, the text box should total up the carried over amount and the page 2 amount and so on. Therefore, page header of page 3 carries over to total page amounts from pages 1 & 2.
From lots of reading on forums, I understand that this cannot be a simple SUM method as this doesnt work in report page headers and footer.
Does this make things simpler?
Regards,
Jo
 

vbaInet

AWF VIP
Local time
Today, 07:42
Joined
Jan 22, 2010
Messages
26,374
Only just had some time to produce a sample. See if the attached is what you're after.

I've saved it as a 2000 format just in case you didn't have 2007. Have a look at the code and what it does.
 

Attachments

  • ReportPages.mdb
    276 KB · Views: 196

horseridingjo

New member
Local time
Today, 07:42
Joined
Jul 7, 2010
Messages
8
Hi,
Its all great except the "txtPgFootSum" which adds the page amount totals need to be adding the previous page totals also. Like a running sum of that page and previous page amounts. Other than that its great thanks.
Regards,
Jo
 

horseridingjo

New member
Local time
Today, 07:42
Joined
Jul 7, 2010
Messages
8
Hi,
Thank you vbaInet. After your help of looking at it another way I finally went back to my code and noticed that it was all working except when on printing giving me funny double/treble figures. I have finally worked out a coding error that was adding two values and not resetting the page value that was throwing it all out. I am now pleased to say that I have managed to get a working copy when viewed AND printed!!! Hoorah.

Many thanks again for your help and patience.
 

vbaInet

AWF VIP
Local time
Today, 07:42
Joined
Jan 22, 2010
Messages
26,374
Hi,
Its all great except the "txtPgFootSum" which adds the page amount totals need to be adding the previous page totals also. Like a running sum of that page and previous page amounts. Other than that its great thanks.
Regards,
Jo
Hmm... I thought you wanted the Header to display the sums from previous pages.

Hi,
Thank you vbaInet. After your help of looking at it another way I finally went back to my code and noticed that it was all working except when on printing giving me funny double/treble figures. I have finally worked out a coding error that was adding two values and not resetting the page value that was throwing it all out. I am now pleased to say that I have managed to get a working copy when viewed AND printed!!! Hoorah.

Many thanks again for your help and patience.
Glad you got it working.
 

Users who are viewing this thread

Top Bottom