Cancel Print

A

AHopper

From a form I open a dialog box which is used to enter the
criteria to print a report. When the "Print" command
button is clicked the report begins to print.
Dim stDocName As String

stDocName = "AnalysisRevised"
DoCmd.Hourglass True
DoCmd.Echo False
DoCmd.OpenReport stDocName, acNormal, , "[JobNumber]=
[Forms]![AnalysisDialogBox]![JobNumber]"
DoCmd.Hourglass False
DoCmd.Echo True

The report contains code in the On Print event of both the
header and detail section. The report prints correctly,
however, there is a message box which appears(I believe it
is part of Microsoft Access print process because I did
not create it). The message indicates the print status (1
of 10 etc.) and it has a Cancel button. If the Cancel
button is pressed the application freezes and has to be
closed. I do not mind having the message box or the cancel
option, however, I would like to have it work properly so
the application does not freeze. If it will not work
properly, is there a way to have it not appear?

Thank you for your help

Allan
 
W

Wayne Morgan

You currently have Hourglass=True and Echo=False. When you cancel the print,
there is probably an error generated in the DoCmd.OpenReport line about the
action being canceled. Since you have things "locked up" as described above,
you don't see the error message; so, it just sits there waiting for you to
respond to something you can't see. You need to have an error handler. In
the error handler, reset the Hourglass and Echo then pop-up a message box
with the error message or, in this case, since you know what generated the
error and everything is fine, check for the error number and if that is the
number do a Resume Next or whatever you want to do if the print is canceled.

To check to see if this is the problem, comment out the Hourglass and Echo
lines and see what happens.
 
A

AHopper

Wayne,
I did what you suggested and I did get a Microsoft Access
message box "The OpenReport action was canceled."

As I mentioned in my original post I have code in the
OnPrint event of the header and detail section of the
report and there is an error handler in the OnClick event
of the "Print" command button. I left in the hourglass and
echo to show how they are placed in the code.

On Error GoTo Err_PrintAnalysisRevisedReport_Click

Dim stDocName As String

stDocName = "AnalysisRevised"
DoCmd.Hourglass True
DoCmd.Echo False
DoCmd.OpenReport stDocName, acNormal, , "[JobNumber]=
[Forms]![SpoilageAnalysisDialogBox]![JobNumber]"
DoCmd.Hourglass False
DoCmd.Echo True
End With
Exit_PrintAnalysisRevisedReport_Click:
Exit Sub

Err_PrintAnalysisRevisedReport_Click:
MsgBox Err.Description
Resume Exit_PrintAnalysisRevisedReport_Click
End Sub

Would the following be an acceptable alternative to
leaving out the Hourglass and Echo?

Err_PrintAnalysisRevisedReport_Click:
DoCmd.Hourglass False
DoCmd.Echo True
MsgBox Err.Description
Resume Exit_PrintAnalysisRevisedReport_Click
End Sub

Thank you very much for your help.

Allan
-----Original Message-----
You currently have Hourglass=True and Echo=False. When you cancel the print,
there is probably an error generated in the
DoCmd.OpenReport line about the
action being canceled. Since you have things "locked up" as described above,
you don't see the error message; so, it just sits there waiting for you to
respond to something you can't see. You need to have an error handler. In
the error handler, reset the Hourglass and Echo then pop- up a message box
with the error message or, in this case, since you know what generated the
error and everything is fine, check for the error number and if that is the
number do a Resume Next or whatever you want to do if the print is canceled.

To check to see if this is the problem, comment out the Hourglass and Echo
lines and see what happens.

--
Wayne Morgan
Microsoft Access MVP


From a form I open a dialog box which is used to enter the
criteria to print a report. When the "Print" command
button is clicked the report begins to print.
Dim stDocName As String

stDocName = "AnalysisRevised"
DoCmd.Hourglass True
DoCmd.Echo False
DoCmd.OpenReport stDocName, acNormal, , "[JobNumber] =
[Forms]![AnalysisDialogBox]![JobNumber]"
DoCmd.Hourglass False
DoCmd.Echo True

The report contains code in the On Print event of both the
header and detail section. The report prints correctly,
however, there is a message box which appears(I believe it
is part of Microsoft Access print process because I did
not create it). The message indicates the print status (1
of 10 etc.) and it has a Cancel button. If the Cancel
button is pressed the application freezes and has to be
closed. I do not mind having the message box or the cancel
option, however, I would like to have it work properly so
the application does not freeze. If it will not work
properly, is there a way to have it not appear?

Thank you for your help

Allan


.
 
W

Wayne Morgan

Err_PrintAnalysisRevisedReport_Click:
DoCmd.Hourglass False
DoCmd.Echo True
MsgBox Err.Description
Resume Exit_PrintAnalysisRevisedReport_Click
End Sub

This looks good, but I would add one more thing. You probably don't really
care about this error, since you told it to cancel you really don't need
Access telling you that it was canceled.

Err_PrintAnalysisRevisedReport_Click:
DoCmd.Hourglass False
DoCmd.Echo True
If Err.Number = 1234 Then
'This is the Cancel error so just keep going
Resume Next 'or wherever your prefer to resume
End If
MsgBox "Error #" & Err.Number & vbCrLf & Err.Description
Resume Exit_PrintAnalysisRevisedReport_Click
End Sub

This will keep the error message from popping up if it is the expected
error, if not, then you'll still get the message box. I don't remember the
error number right off-hand, but if you add that to your message box you can
find out what it is. Just use that number instead of 1234.

--
Wayne Morgan
MS Access MVP


AHopper said:
Wayne,
I did what you suggested and I did get a Microsoft Access
message box "The OpenReport action was canceled."

As I mentioned in my original post I have code in the
OnPrint event of the header and detail section of the
report and there is an error handler in the OnClick event
of the "Print" command button. I left in the hourglass and
echo to show how they are placed in the code.

On Error GoTo Err_PrintAnalysisRevisedReport_Click

Dim stDocName As String

stDocName = "AnalysisRevised"
DoCmd.Hourglass True
DoCmd.Echo False
DoCmd.OpenReport stDocName, acNormal, , "[JobNumber]=
[Forms]![SpoilageAnalysisDialogBox]![JobNumber]"
DoCmd.Hourglass False
DoCmd.Echo True
End With
Exit_PrintAnalysisRevisedReport_Click:
Exit Sub

Err_PrintAnalysisRevisedReport_Click:
MsgBox Err.Description
Resume Exit_PrintAnalysisRevisedReport_Click
End Sub

Would the following be an acceptable alternative to
leaving out the Hourglass and Echo?

Err_PrintAnalysisRevisedReport_Click:
DoCmd.Hourglass False
DoCmd.Echo True
MsgBox Err.Description
Resume Exit_PrintAnalysisRevisedReport_Click
End Sub

Thank you very much for your help.

Allan
-----Original Message-----
You currently have Hourglass=True and Echo=False. When you cancel the print,
there is probably an error generated in the
DoCmd.OpenReport line about the
action being canceled. Since you have things "locked up" as described above,
you don't see the error message; so, it just sits there waiting for you to
respond to something you can't see. You need to have an error handler. In
the error handler, reset the Hourglass and Echo then pop- up a message box
with the error message or, in this case, since you know what generated the
error and everything is fine, check for the error number and if that is the
number do a Resume Next or whatever you want to do if the print is canceled.

To check to see if this is the problem, comment out the Hourglass and Echo
lines and see what happens.

--
Wayne Morgan
Microsoft Access MVP


From a form I open a dialog box which is used to enter the
criteria to print a report. When the "Print" command
button is clicked the report begins to print.
Dim stDocName As String

stDocName = "AnalysisRevised"
DoCmd.Hourglass True
DoCmd.Echo False
DoCmd.OpenReport stDocName, acNormal, , "[JobNumber] =
[Forms]![AnalysisDialogBox]![JobNumber]"
DoCmd.Hourglass False
DoCmd.Echo True

The report contains code in the On Print event of both the
header and detail section. The report prints correctly,
however, there is a message box which appears(I believe it
is part of Microsoft Access print process because I did
not create it). The message indicates the print status (1
of 10 etc.) and it has a Cancel button. If the Cancel
button is pressed the application freezes and has to be
closed. I do not mind having the message box or the cancel
option, however, I would like to have it work properly so
the application does not freeze. If it will not work
properly, is there a way to have it not appear?

Thank you for your help

Allan


.
 
A

AHopper

Wayne,
Thank you very much for your time and the valuable
information.

Allan
-----Original Message-----
Err_PrintAnalysisRevisedReport_Click:
DoCmd.Hourglass False
DoCmd.Echo True
MsgBox Err.Description
Resume Exit_PrintAnalysisRevisedReport_Click
End Sub

This looks good, but I would add one more thing. You probably don't really
care about this error, since you told it to cancel you really don't need
Access telling you that it was canceled.

Err_PrintAnalysisRevisedReport_Click:
DoCmd.Hourglass False
DoCmd.Echo True
If Err.Number = 1234 Then
'This is the Cancel error so just keep going
Resume Next 'or wherever your prefer to resume
End If
MsgBox "Error #" & Err.Number & vbCrLf & Err.Description
Resume Exit_PrintAnalysisRevisedReport_Click
End Sub

This will keep the error message from popping up if it is the expected
error, if not, then you'll still get the message box. I don't remember the
error number right off-hand, but if you add that to your message box you can
find out what it is. Just use that number instead of 1234.

--
Wayne Morgan
MS Access MVP


Wayne,
I did what you suggested and I did get a Microsoft Access
message box "The OpenReport action was canceled."

As I mentioned in my original post I have code in the
OnPrint event of the header and detail section of the
report and there is an error handler in the OnClick event
of the "Print" command button. I left in the hourglass and
echo to show how they are placed in the code.

On Error GoTo Err_PrintAnalysisRevisedReport_Click

Dim stDocName As String

stDocName = "AnalysisRevised"
DoCmd.Hourglass True
DoCmd.Echo False
DoCmd.OpenReport stDocName, acNormal, , "[JobNumber] =
[Forms]![SpoilageAnalysisDialogBox]![JobNumber]"
DoCmd.Hourglass False
DoCmd.Echo True
End With
Exit_PrintAnalysisRevisedReport_Click:
Exit Sub

Err_PrintAnalysisRevisedReport_Click:
MsgBox Err.Description
Resume Exit_PrintAnalysisRevisedReport_Click
End Sub

Would the following be an acceptable alternative to
leaving out the Hourglass and Echo?

Err_PrintAnalysisRevisedReport_Click:
DoCmd.Hourglass False
DoCmd.Echo True
MsgBox Err.Description
Resume Exit_PrintAnalysisRevisedReport_Click
End Sub

Thank you very much for your help.

Allan
-----Original Message-----
You currently have Hourglass=True and Echo=False. When you cancel the print,
there is probably an error generated in the
DoCmd.OpenReport line about the
action being canceled. Since you have things "locked
up"
as described above,
you don't see the error message; so, it just sits there waiting for you to
respond to something you can't see. You need to have an error handler. In
the error handler, reset the Hourglass and Echo then
pop-
up a message box
with the error message or, in this case, since you know what generated the
error and everything is fine, check for the error
number
and if that is the
number do a Resume Next or whatever you want to do if
the
print is canceled.
To check to see if this is the problem, comment out the Hourglass and Echo
lines and see what happens.

--
Wayne Morgan
Microsoft Access MVP


"AHopper" <[email protected]> wrote
in
message
From a form I open a dialog box which is used to
enter
the
criteria to print a report. When the "Print" command
button is clicked the report begins to print.
Dim stDocName As String

stDocName = "AnalysisRevised"
DoCmd.Hourglass True
DoCmd.Echo False
DoCmd.OpenReport stDocName,
acNormal, , "[JobNumber]
=
[Forms]![AnalysisDialogBox]![JobNumber]"
DoCmd.Hourglass False
DoCmd.Echo True

The report contains code in the On Print event of
both
the
header and detail section. The report prints correctly,
however, there is a message box which appears(I
believe
it
is part of Microsoft Access print process because I did
not create it). The message indicates the print
status
(1
of 10 etc.) and it has a Cancel button. If the Cancel
button is pressed the application freezes and has to be
closed. I do not mind having the message box or the cancel
option, however, I would like to have it work
properly
so
the application does not freeze. If it will not work
properly, is there a way to have it not appear?

Thank you for your help

Allan





.


.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Button Coding 1
Syntax for number of copies to print? 1
StartDate, EndDate 3
Debugger runs but unwanted 8
Access Choosing Printer VBA Access 0
Date Criteria problem 2
Print Button Code 2
Exporting a Report to Excel 2

Top