Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Printing the last page of a report 1

Status
Not open for further replies.

danwand

Programmer
Jun 8, 2003
100
GB
Hi,

I have created an application where users can add to a patient's physical observation records which is done through a form. Once they save the new record i want to automatically open a report of all previous physical observations for that patient, go to the last page of the report and print it out.

I have already created the query and the report to show physical obervations for the selected patient which works fine.

But rather than have the user navigate to the last page of the report, access the print dialog and select page 3 of 3 for printout i want the last page automatically sent to the printer (i'm not concerned as to whether the report is visible or not during this process).

So far i have managed to get the report to go to the last page by using the following code:

Private Sub Report_Open(Cancel As Integer)
SendKeys "{End}"
End Sub

But how do i print this last page programmatically.

I guess ideally i would like this to all happen in the background so that once and new record has been added and the save button has been pressed all the user has to do is go the printer and collect the 1 page report.

Any help would be appreciated.
 
if your observation table has a primary key

base your reports record source of just the last observation
 
Thanks for the reply but......

Maybe i should outline the working procedures involved...

There is a paper based observations file with a section for each patient. Each patient can have 1 or many pages of observations. Each page can hold up to 18 separate observation records.

The old process was to simply write the next observation down on the next available space on the last of the patients observation sheets.

The process now will be to enter the latest observations on the database, print out the observations report and replace the last page in the observations file.

So if the patient already has 3 pages of observations in the observations file, all we want to do is replace the last of these 3 pages as it will now have the latest observation on it.

The actual access report will have 3 pages but it will be pointless printing out the first 2 pages because they will be the same as those already in the observations file we are just interested in the last page because it will have an extra observation on it.

Again rather than getting the user to go through the process of selecting which page to print i want to automate the process so that all they do is enter and save a record and then go to the printer, get the printout, go to the observation file and replace the last page.
 
If you are using Access 2002 or greater, the new printer object model does the work nicely. You can pass it the page to be printed with the [Pages] report parameter.
Have a look on how to do it here:

"Don't be irreplaceable. If you can't be replaced, you can't be promoted."
 
Thanks genomon,

Thats exactly the type of solution I need, however my clients PCs have office 2000 not 2002.

I don't suppose there is a similar method for office 2000 that anyone knows about?
 
I have just visited the link, downloaded the example, cut pasted and manipulated the code/modules to suit my purpose and it works perfectly for my needs but again the major problem is that the client uses office 2000.

E.g. i can now use VBA to automatically print the last page of the report after the user has saved a new entry without the user actually having to open the report and navigate around the print diaog box.

So if anyone else has a similar method that i can use with office 2000 please let me know.
 
Ok i have solved it....


I was suprised how easy it was....

I opened a recordset to the observations table, counted the number of records for the selected patient, divided the number of records by 18 to calculated how many pages of record they will have, used ('mod' recordcount 18) to determine if an extra page is required...
So if patient has 37 records, from the first division we get 2 (37/18 = 2) so i know there will be at least 2 pages of records. Then from the second mod calculation we get 1 (37 mod 18 = 1) so i then know that there will be 3 pages of records...

Then i simply used the following code:

DoCmd.OpenReport "rptD1-F10LP", acHidden

DoCmd.SelectObject acReport, "rptD1-F10LP"
DoCmd.printout acPages, numP, numP

With numP being the calculation for the number of pages i made previously, so numP = 3 ...so print page range from 3 to 3.


I guess its easy once you know.....

Thanks for setting me in the right direction.
 
Office 2000! You'd be looking at changing your car if it was that old!
Just an observation.

Ian Mayor (UK)
Program Error
9 times out of 10 I know what I'm talking about. This must be my tenth reply.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top