UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> Counting Pages On An Open Report, Any Version    
 
   
shadow
post Aug 1 2019, 12:23 PM
Post#1



Posts: 280
Joined: 19-April 04
From: Toronto


I am aware that a report can display the number of pages just by putting a textbox that says =[Pages] on the report.

What I am trying to do is get the number of pages on an open report, but from a form (I can explain why later if anyone is interested).

This should be a matter of saying "intNumberOfPages = Reports!myReport.pages" BUT this only seems to work if you happen to have a textbox on the open report that contains the number of pages. Otherwise it will return 0.

My question is if there is a way to get the number of pages on the open report WITHOUT having a textbox on the report.

Thank you

Go to the top of the page
 
Larry Larsen
post Aug 1 2019, 12:39 PM
Post#2


UA Editor + Utterly Certified
Posts: 24,355
Joined: 26-August 02
From: Melton Mowbray,Leicestershire (U.K)


Hi

I haven't used this process/procedure for a number of years, it may help.

Public function:

CODE
Public Function fGetPageCount(strReportName)

'Open the report in invisible mode (hidden)
DoCmd.OpenReport strReportName, acViewPreview, , , acHidden

'Get the page count
fGetPageCount = Reports(strReportName).Pages

'Close the report so you can reopen it for the user
DoCmd.Close acReport, strReportName, acSaveNo

End Function


HTH's
thumbup.gif

--------------------
"Time...We have exactly the same number of hours per day that were given to Helen Keller, Pasteur, Michaelangelo, Mother Teresa, Leonardo da Vinci, Thomas Jefferson, and Albert Einstein"
H. Jackson Brown
Go to the top of the page
 
projecttoday
post Aug 1 2019, 12:42 PM
Post#3


UtterAccess VIP
Posts: 10,954
Joined: 10-February 04
From: South Charleston, WV


Make the textbox not visible.

--------------------
Robert Crouser
Go to the top of the page
 
shadow
post Aug 1 2019, 12:58 PM
Post#4



Posts: 280
Joined: 19-April 04
From: Toronto


Thanks for the answers, guys smile.gif

My bad; I wasn't more specific.

My project has hundreds of reports. Some have a textbox with a page count and some don't (i.e. I was lazy when designing the report). The functionality that I am trying to achieve is to grab the number of pages of the most recently opened report regardless of whether I put the page-counter textbox on it or not. In other words, I won't know in advance what report is open on the screen at runtime or whether it happens to have a page counter.

Is that more clear?

Thanks again!
Go to the top of the page
 
projecttoday
post Aug 1 2019, 06:50 PM
Post#5


UtterAccess VIP
Posts: 10,954
Joined: 10-February 04
From: South Charleston, WV


I don't know if there is a way to do this with system tables or GetFocus, but one obvious way would be to save the necessary information. You could use a table or a global array.

--------------------
Robert Crouser
Go to the top of the page
 
shadow
post Aug 1 2019, 08:12 PM
Post#6



Posts: 280
Joined: 19-April 04
From: Toronto


@projecttoday:

one obvious way would be to save the necessary information. You could use a table or a global array.


That would assume knowing how many pages the report would be in advance of runtime. The user might have 1 or 1000 pages, depending on the data in the report.
Go to the top of the page
 
projecttoday
post Aug 2 2019, 02:13 AM
Post#7


UtterAccess VIP
Posts: 10,954
Joined: 10-February 04
From: South Charleston, WV


You're trying to grab the number of pages of the most recently opened report. Why do you need to do that in advance of opening the report?

--------------------
Robert Crouser
Go to the top of the page
 
isladogs
post Aug 2 2019, 02:50 AM
Post#8


UtterAccess VIP
Posts: 1,602
Joined: 4-June 18
From: Somerset, UK


To clarify, you want the number of pages on the most recently opened report AFTER it has been run.

If that's the case, you can save the Pages value as a global variable or Tempvar for later use.
If so, might be a good idea to also save the report name as another variable/TempVar.

Of course, if records are later added / deleted, that number could change ....

If you need this for all reports, save the values into a table or array as already stated....but I cannot see any reason for doing so.

Personally, I would just add a page counter to all reports where you didn't do so previously. It only takes a few seconds to copy & paste = [Page] of [Pages] into the report page footer section

--------------------
Go to the top of the page
 
projecttoday
post Aug 2 2019, 03:12 AM
Post#9


UtterAccess VIP
Posts: 10,954
Joined: 10-February 04
From: South Charleston, WV


shadow wants
QUOTE
the number of pages of the most recently opened report
Does that mean he/she knows which report that is? I would guess not. So if I'm right a list of some kind of all open reports by name with the time that they were opened (and the number of pages) is needed. (Is there a system table for this?) To get the desired result, the list will have to be searched on the max date/time. So unless there is an array version of tempvars that won't work. You would need a global array or a table. Table coding would be slightly simpler. You could use Dmax. Array coding would run fast as lightning.

When the report is closed the entry has to be deleted.

I agree, if my understanding is correct, no need to know the number of pages before the report has opened.

Awaiting more info from shadow.

--------------------
Robert Crouser
Go to the top of the page
 
shadow
post Aug 2 2019, 09:54 AM
Post#10



Posts: 280
Joined: 19-April 04
From: Toronto


I'm sorry if I wasn't more clear.

I didn't think I needed to explain the need in order to ask the question but I am afraid I caused confusion!

The project that I'm working on is to create fax functionality using Twilio. Colin helped with SMS and it's been a real success in my own project and now I'm doing faxing.

If anyone is interested, I am more than happy to share my process, code and and reason for the need on the forum.

When you send a fax using my interface, it creates a cover page and attaches it to the report you are faxing. It is standard practice to have a box on a fax cover sheet indicating the number of pages.

The way my fax interface works is that you can open ANY report in the system and then open the fax interface, fill out the cover page and click Send Fax and it sends.

The application probably has 200 reports. When the user runs the report (e.g. a sales report that we want to fax to the accountant). I don't know if the office running the report will be doing it for one month, a quarter, a year, year to date or how many sales they have for the interval. So there's no way to have a variable associated with a report. Every office using the interface has a different volume of sales and can be running it for any interval.

The nature of my question was based on the fact that it seems that even when the report is open, you can only get the number of pages IF there is a box indicating this number. I was hoping that there was another way but it seems that Colin's approach (which was what I expected) is the only way to go: make sure that every report has the appropriate box.

As far as getting the most recently opened report, that's actually easy using the Reports collection:

Here's how I did it:

CODE
i = -1
  For Each Report In Reports
     i = i + 1
   Next
  If i > -1 Then
    Set rptExport = Reports(i)
  End if


rptExport will be the report opened more recently.

Once again, thanks a lot for the help and if anyone's interested in the project, I'm happy to share it!

Cheers
Go to the top of the page
 
isladogs
post Aug 2 2019, 12:16 PM
Post#11


UtterAccess VIP
Posts: 1,602
Joined: 4-June 18
From: Somerset, UK


At least I can understand what this is for now....
I remember being surprised when you talked about adding faxing capability some time ago.
In order to display the total pages, Access has to process each report twice.
Once to run through and calculate the total and again to display that total on each page.
I don't think saving the total is worthwhile and it could easily be different on next opening the report.
So I think you need to scan the report to get the total, then do the faxing.

You might find this link useful: https://stackoverflow.com/questions/3357003...n-vba-ms-access

Another method which may work for you is if each page contains a known number of records. You can then do a record count divided by records per page.
This will be much faster if you have a huge number of records.
For example I have a postcodes report which can have 2.6 million postcodes.
I use the above method to warn the user that the report contains around 60,000 pages so shouldn't be printed.

As a side note, the Pages property is an integer variable. If your report exceeds the integer limit of 32767 the Pages value is shown as a negative number.
For more info on this oddity, and how I did a workround, can be found here Negative Total Pages on Report

--------------------
Go to the top of the page
 
shadow
post Aug 2 2019, 12:55 PM
Post#12



Posts: 280
Joined: 19-April 04
From: Toronto


OK, then question answered smile.gif

I think that I'll take the time to add the box to each report that doesn't have it.

There's no way any report will have more than 20 pages so that's not a concern.

Thanks again and cheers...
Go to the top of the page
 
isladogs
post Aug 2 2019, 02:36 PM
Post#13


UtterAccess VIP
Posts: 1,602
Joined: 4-June 18
From: Somerset, UK


On behalf of all of us, you're very welcome

--------------------
Go to the top of the page
 


Custom Search


RSSSearch   Top   Lo-Fi    15th September 2019 - 09:07 AM