on 12-08-2014 5:11 AM
Hi,
In my Document, there are 2 Reports.
I need to have total pages for the entire document.
So, in my After
Private Sub Document_AfterRefresh()
Dim myDocument As Document
Set myDocument = Application.Documents(1)
g_total1 = myDocument.Reports(1).NumberOfPages()
g_total2 = myDocument.Reports(2).NumberOfPages()
For i = 1 To myDocument.Variables.Count
If myDocument.Variables(i).Name = "g_total1" Then
myDocument.Variables(i).Value = g_total1
End If
Next
'''' Trying different approach to assign a value to report variable
myDocument.Variables("g_total2").Value = g_total2
End Sub
For sake of testing, whether I can change the variable value in my report, I coded the followings in my Report 1 footer.
="Page " & FormatNumber (Page() , "#") & " of " & <g_total1>
g_total1 was declared as a dimension, formula = 1
The main issue I had is I am not able to read from the macro value. I inserted MsgBox for debugging purposes and it is showing the correct page number.
Is my approach correct ? Thanks.
After much testing, I managed to get it done ... just share with you how I get it to work.
Just change the .Value to .Formula and the numbers will show up on the report itself.
1) Add variables in the document to store each report total page count.
g_total =0
g_total1 =0
g_total2 =0
2) Use macro to assign the number of pages for each report in the entire document into variable.
Private Sub Document_AfterRefresh()
Dim myDocument As Document
Set myDocument = Application.Documents(1)
g_total1 = myDocument.Reports(1).NumberOfPages()
g_total2 = myDocument.Reports(2).NumberOfPages()
g_total = g_total1 + g_total2
myDocument.Variables("g_total").Formula = "=" & g_total
myDocument.Variables("g_total1").Formula = "=" & g_total1
myDocument.Variables("g_total2").Formula = "=" & g_total2
End Sub
3) In the footer, change the NumberofPages() to the variable to sum up all the pages for each report
Assume you are in report 1 footer
="Page " & FormatNumber (Page() , "#") & " of " & <g_total>
Then report2 footer
="Page " & FormatNumber (Page()+<g_total1> , "#") & " of " & <g_total>
Keep on adding the total from the previous report
Now, the final tasks ... I haven't test it on Infoview but the above method works fine in development environment.
Hope the future release can provide a function for total pages in a document ...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
81 | |
10 | |
10 | |
9 | |
7 | |
6 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.