I am stuck on this algorithm and not quite sure how to approach it. My program needs to calculate the number of pages prior to sending it out to the printer. I know that I can use printer.page to get the page number but I need the total pages printed on the cover page. Here is what I have.
The number of records per page is set at 8. So each page contains no more than 8 records. I can get the record count by table1.recordset.recordcount, so I can get the total records. The problem is this.
If I make dTotalPages = table1.recordset.recordcount / 8 and the total records are not divisible by 8 the iTotalPages would contain a fraction if it was a double instead of an integer. So for instance if the record count is 9 then the iTotalPages = 1 So the output would produce 2 pages, 8 on the first page and 1 on the second page. So the dTotalPages should equal 2.
Here is what I have tried.
VB Code:
dim iTotalPages as Integer dim dTotalRecords as Double dim X as Double dim Y as Integer 'dTotalRecords = table1.recordset.recordcount 'commented out for testing dTotalRecords = 9 If dTotalRecords < 1 then iTotalPages = 1 Else iTotalPages = dTotalRecords / 8 X = val(right(dTotalPages, 4)) if X > 0 then X = 1 End If Y = iTotalPages 'only gets the whole number iTotalPages = X + Y End If
The resulte is still 1 page and should be 2 pages in this test.




Reply With Quote