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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

pause printing between pages but not in Preview mode

Status
Not open for further replies.

THWatson

Technical User
Apr 25, 2000
2,601
CA
Using Access 2000

I have the following code on the Page event of a 2 page report. Page 2 is forced by a page break in the report.
Code:
Private Sub Report_Page()
If Me.Page > 1 Then
Call MsgBox("     Please turn paper over" _
            & vbCrLf & "and press OK to print page 2." _
            , vbExclamation, "Pause printing")
End If
End Sub

This does exactly what I want in Print mode. But I do not want the message box, and print to pause, in Preview mode.

Is there code I can add to suppress the message box in Preview mode? Or different code I can use for this?

Tom
 
Here's the full code in the module behind the report, in case it helps somebody else...

Code:
Private Printing As Integer

Private Sub Report_Activate()
    'Occurs only when previewing
    Printing = -1
End Sub

Private Sub Report_Deactivate()
    'Reset for next time
    Printing = 0
End Sub

Private Sub Report_Page()
If Me.Page > 1 And Printing > 0 Then
Call MsgBox("     Please turn paper over" _
           & vbCrLf & "and press OK to print page 2." _
            , vbExclamation, "Pause printing")
End If
End Sub

Private Sub ReportHeader_Print(Cancel As Integer, PrintCount As Integer)
    'Occurs when previewing and when printing
    Printing = Printing + 1
End Sub

Note: there must be a report header section and the height must be greater than 0, but nothing needs to be in the section.

Tom
 
Found this code on MS Knowledgebase - might be of assistance.


Method One: Use Code to Check the Status of the Report
You can use the AllReports collection to check the status of the report. If the report is currently open in Print Preview view, you can issue a command to close the report and then issue a command to open it for printing. To see an example of how to do this, follow these steps: 1. Create a module, and then type the following line in the Declarations section if it is not already there: Option Explicit


2. Type the following procedure: Public Sub PrintReport(strReportName As String)
Dim accobj As AccessObject

'This function closes the open report and then re-opens it.

Set accobj = application.CurrentProject.AllReports.Item(strReportName)

If accobj.IsLoaded Then
If accobj.CurrentView = acCurViewPreview Then
DoCmd.Close acReport, strReportName
DoCmd.OpenReport strReportName, acViewNormal
End If
Else
DoCmd.OpenReport strReportName, acViewNormal
End If

End Sub


3. To test this procedure: a. Switch back to the Database window and then open your report in Print Preview. Switch back to the Visual Basic Editor.
b. In the Immediate window, type the following, and then press ENTER:
PrintReport "ReportNameHere"

Notice that if your report is closed, you can reopen it and Access will not switch to Design view.
 
payback
Thanks for the input, and for going to the trouble of finding the code on MS Knowledge Base.

Actually, the code I posed above works quite fine. And what I want to have happen is the message box appear in Print mode, so that it pauses the printing in order for the user to turn over the page of paper and print on the opposite side, and resumes printing when the user clicks the OK button on the message box.

My issue was that I didn't want the message box appearing in Preview mode, and the code I posted solves that.

Thanks again. I'll try what you found and see what it does.

Tom
 
payback
I tested out the code you posted, because I was interested in seeing what it would do.

There is a problem with this line...
If accobj.CurrentView = acCurViewPreview Then

The code won't compile with "acCurViewPreview." It does compile when I changed that to "acViewPreview."

However, when I do step 3 and attempt to run the report in the Immediate window, I get a runtime error 438 "Object doesn't support this property or method."

Checking Help resulted in the fact that the Current View property is only available in Forms or Data Access Pages.

So I went to the Knowledge Base, and it appears that the procedure applies to Access 2002. I am using Access 2000, so it looks as if this procedure won't work in Access 2000.

Tom
 
Code:
for i = 1 to lastpage
DoCmd.PrintOut , i, i+1
    'wait until key pressed
    MsgBox "Place a label in the printer tray" & vbCrLf & "Press enter or click on OK to print next page", vbOKOnly, "Waiting to print page " & Str(i)
next i


arguments for printout are ...
printout (PrintRange, PageFrom, PageTo, PrintQuality, Copies, CollateCopies)

Program Error
Programmers do it one finger at a time!
 
ProgramError
For some reason, the code I was using was working fine until using a different printer, and now it's acting up. So I am trying your code, but I can't figure out where to put it.

Because this is the issue...I want the code to work only when printing, and not in Preview mode.

Tom
 
Do you have the Openargs option when opening a report. I have XP (2002) but a database in 2000 file format gives me that option.

Therefore if your code says something like -

Docmd.OpenReport "reportname",acViewPreview,,reportcriteria,,"Preview"

In the report where you check the page number, write in -

If Openargs = "Preview" Then
Call msgbox etc.
End If

You might have to set Openargs to null if printing from the toolbar.

Just an idea - not proven yet until you try it.

 
payback
Thanks for the suggestion.

As near as I can see, in Access 2000 OpenArgs can be used to open forms but not reports. Microsoft must have added that option to later versions of Access.

The weird thing here is that my code worked just fine on two different printers at my home...but now at another location with a different printer things just lock up and nothing prints until the OK button is pressed, all of which totally defeats what I was trying to do.

Maybe it's a printer-specific issue. Oy.

Tom
 
It appears this is definitely a "printer specific" issue as I forwarded the db to another person and the code works just fine.

Tom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top