Robert Wardlow
asked on
Access Report Pagination
I am printing a lab report that contains many 1, 2 or 3 page reports to different people.
I am using a group header for their property address (1 per person)
In the VBA code for the group header I am setting Page = 1 to begin each persons report at page 1.
I would like to use the "of" page number function. (Page 1 of 2)
But the "of" number is the number of pages in the entire report for everyone. (Page 1 of 63 for example)
Is there a way to calculate the "of number" for each group?
What is the syntax for that command?
Thank you in advance for your help.
Bob
I am using a group header for their property address (1 per person)
In the VBA code for the group header I am setting Page = 1 to begin each persons report at page 1.
I would like to use the "of" page number function. (Page 1 of 2)
But the "of" number is the number of pages in the entire report for everyone. (Page 1 of 63 for example)
Is there a way to calculate the "of number" for each group?
What is the syntax for that command?
Thank you in advance for your help.
Bob
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you both for your suggestions. I am trying the solution from JDettman first.
JDettman:
The instructions go step by step but
There is one part of the instructions that I don't know how to do.
It says "Define a variable for a Database Object, a variable for a RecordSet object" but it doesn't say where.
It says to "append the following code to any existing code"
Can I literaly put it anywhere?
Like in the group header or footer of the report?
Or does it go in a database module? If so, which one.
I don't understand how it can go anywhere?
Thanks in advance
Bob
JDettman:
The instructions go step by step but
There is one part of the instructions that I don't know how to do.
It says "Define a variable for a Database Object, a variable for a RecordSet object" but it doesn't say where.
It says to "append the following code to any existing code"
Can I literaly put it anywhere?
Like in the group header or footer of the report?
Or does it go in a database module? If so, which one.
I don't understand how it can go anywhere?
Thanks in advance
Bob
<<It says "Define a variable for a Database Object, a variable for a RecordSet object" but it doesn't say where.>>
You would define those in the report Declarations section. Open the report in design view, select view/code. The declarations section is right at the top of the code window. Variables dim'd here are available to all procedures in the report and will exist for the life of the report.
<<It says to "append the following code to any existing code">>
It's talking about the reports code. You may or may not have existing code.
JimD.
You would define those in the report Declarations section. Open the report in design view, select view/code. The declarations section is right at the top of the code window. Variables dim'd here are available to all procedures in the report and will exist for the life of the report.
<<It says to "append the following code to any existing code">>
It's talking about the reports code. You may or may not have existing code.
JimD.
ASKER
many thanks
ASKER
JeffCoachman,
I am trying to use your solution by modifying your code to match my structure. But I think I have a syntax problem that I can't seem to figure out. Below is my code
[Results Mail Full] is a query
[Property Address 1] is a field in [Results Mail Full] query
I want to print 1 report for each property address
If I specify the address like below it works:
"[Property Address 1]= '123 main street'"
But this doesn't work
"[Property Address 1]=" & rst![Property Address 1]
I get this error
Runtime error 3075
Syntax Error (Missing Operator)
What is the correct syntax?
thank you in advance for your help.
Bob
Dim rst As DAO.Recordset
Set rst = CurrentDb.OpenRecordset("S ELECT [Results Mail Full].[property address 1] FROM [Results Mail Full]")
rst.MoveFirst
Do While Not rst.EOF
DoCmd.OpenReport "Result full", acViewPreview, , "[Property Address 1]=" & rst![Property Address 1]
rst.MoveNext
Loop
MsgBox "Done", vbInformation
'recordset cleanup
rst.Close
Set rst = Nothing
I am trying to use your solution by modifying your code to match my structure. But I think I have a syntax problem that I can't seem to figure out. Below is my code
[Results Mail Full] is a query
[Property Address 1] is a field in [Results Mail Full] query
I want to print 1 report for each property address
If I specify the address like below it works:
"[Property Address 1]= '123 main street'"
But this doesn't work
"[Property Address 1]=" & rst![Property Address 1]
I get this error
Runtime error 3075
Syntax Error (Missing Operator)
What is the correct syntax?
thank you in advance for your help.
Bob
Dim rst As DAO.Recordset
Set rst = CurrentDb.OpenRecordset("S
rst.MoveFirst
Do While Not rst.EOF
DoCmd.OpenReport "Result full", acViewPreview, , "[Property Address 1]=" & rst![Property Address 1]
rst.MoveNext
Loop
MsgBox "Done", vbInformation
'recordset cleanup
rst.Close
Set rst = Nothing
ASKER
This worked great. Thanks
I'll take a look tonight
ASKER
Thanks, but I figured it out. That's why I closed the question and awarded you the points. I was not able to get the other solution to work but I got yours to work.
Thank you both again for your help.
Bob
Thank you both again for your help.
Bob
Thanks,
For the record, JDettman's code link will work.
I had used it a few times.
I thought I had a sample of it, but I cannot find it now.
I use this now.
The code is more complex, but you can basically drop it in, and it will work.
(This code is for a Report Grouped by ShipCountry)
'************ Code Start *************
' This code was originally written by James H Brooks.
' It is not to be altered or distributed,
' except as part of an application.
' You are free to use it in any application,
' provided the copyright notice is left unchanged.
'
' Code Courtesy of
' James H Brooks
'
Dim GrpArrayPage(), GrpArrayPages()
Dim GrpNameCurrent As Variant, GrpNamePrevious As Variant
Dim GrpPage As Integer, GrpPages As Integer
Private Sub PageFooterSection_Format(C ancel As Integer, FormatCount As Integer)
Dim i As Integer
If Me.Pages = 0 Then
ReDim Preserve GrpArrayPage(Me.Page + 1)
ReDim Preserve GrpArrayPages(Me.Page + 1)
GrpNameCurrent = Me!ShipCountry
If GrpNameCurrent = GrpNamePrevious Then
GrpArrayPage(Me.Page) = GrpArrayPage(Me.Page - 1) + 1
GrpPages = GrpArrayPage(Me.Page)
For i = Me.Page - ((GrpPages) - 1) To Me.Page
GrpArrayPages(i) = GrpPages
Next i
Else
GrpPage = 1
GrpArrayPage(Me.Page) = GrpPage
GrpArrayPages(Me.Page) = GrpPage
End If
Else
If Me.Page = Me.Pages Then
Me!ctlGrpPages = ""
Else
Me!ctlGrpPages = Me.ShipCountry & " " & GrpArrayPage(Me.Page) & " of " & GrpArrayPages(Me.Page)
If GrpArrayPage(Me.Page) + 1 = GrpArrayPages(Me.Page) Then
Me.txtPageHeader.Visible = False
Else
Me.txtPageHeader.Visible = True
End If
End If
End If
GrpNamePrevious = GrpNameCurrent
I still feel that you should give the link Jim piosed another try.
My soultion is basically a workaround I came up with for people who were a little afraid of code.
It is slower than the code approaches because it sends one print job to the printer for every group. (Instead of one print job for the entire report)
;-)
Jeff
For the record, JDettman's code link will work.
I had used it a few times.
I thought I had a sample of it, but I cannot find it now.
I use this now.
The code is more complex, but you can basically drop it in, and it will work.
(This code is for a Report Grouped by ShipCountry)
'************ Code Start *************
' This code was originally written by James H Brooks.
' It is not to be altered or distributed,
' except as part of an application.
' You are free to use it in any application,
' provided the copyright notice is left unchanged.
'
' Code Courtesy of
' James H Brooks
'
Dim GrpArrayPage(), GrpArrayPages()
Dim GrpNameCurrent As Variant, GrpNamePrevious As Variant
Dim GrpPage As Integer, GrpPages As Integer
Private Sub PageFooterSection_Format(C
Dim i As Integer
If Me.Pages = 0 Then
ReDim Preserve GrpArrayPage(Me.Page + 1)
ReDim Preserve GrpArrayPages(Me.Page + 1)
GrpNameCurrent = Me!ShipCountry
If GrpNameCurrent = GrpNamePrevious Then
GrpArrayPage(Me.Page) = GrpArrayPage(Me.Page - 1) + 1
GrpPages = GrpArrayPage(Me.Page)
For i = Me.Page - ((GrpPages) - 1) To Me.Page
GrpArrayPages(i) = GrpPages
Next i
Else
GrpPage = 1
GrpArrayPage(Me.Page) = GrpPage
GrpArrayPages(Me.Page) = GrpPage
End If
Else
If Me.Page = Me.Pages Then
Me!ctlGrpPages = ""
Else
Me!ctlGrpPages = Me.ShipCountry & " " & GrpArrayPage(Me.Page) & " of " & GrpArrayPages(Me.Page)
If GrpArrayPage(Me.Page) + 1 = GrpArrayPages(Me.Page) Then
Me.txtPageHeader.Visible = False
Else
Me.txtPageHeader.Visible = True
End If
End If
End If
GrpNamePrevious = GrpNameCurrent
I still feel that you should give the link Jim piosed another try.
My soultion is basically a workaround I came up with for people who were a little afraid of code.
It is slower than the code approaches because it sends one print job to the printer for every group. (Instead of one print job for the entire report)
;-)
Jeff
How to reset the page number and the total page count for each group in a Microsoft Access report
http://support.microsoft.c
Which shows you how to activate a second pass on the report allowing you to pick up the last page of each group (you can use this technique for a lot of different things too, such as table of contents, indexes, etc).
JimD.