J
J.Bennett
I have a database that has three main forms. From one of the forms, the user
can select one of several reports to print by selecting various buttons.
Each button runs an "Event Procedure" so that the reports are filtered so
that only the active record is printed. The commands used (for one of the
buttons) are as follows:
Private Sub PrintDeliveryRpt_Click()
Dim strWhere As String
If Me.Dirty Then 'Save any edits.
Me.Dirty = False
End If
If Me.NewRecord Then 'Check there is a record to print
MsgBox "Select a record to print"
Else
strWhere = "[CUSTID] = " & Me.[CUSTID]
DoCmd.OpenReport "DeliveryQuestionReport", acViewPreview, , strWhere
End If
End Sub
These commands open the print preview. The user can then select the "Print"
icon to actually print the document.
Here's the question: What do I need to add/change/modify etc. to the
commands above so that the print dialog is automatically invoked, and that
once the user either selects "print" or "cancel" the preview is closed. Not
knowing what to do, I started trying differnt things to attempt to accomplish
this task. I
tried modifying the "Else" condition by adding the "RunCommand acCmdPrint"
and the "RunCommand acCmdClose" as follows:
Else
strWhere = "[CUSTID] = " & Me.[CUSTID]
DoCmd.OpenReport "QuoteOutputReport", acViewPreview, , strWhere
RunCommand acCmdPrint
RunCommand acCmdClose
End If
This works as long as the user selects "Print" once the print dialog box
opens. The report prints and the preview closes. However, if the user
decides to "Cancel" the printing, it gives an error and prompts the user to
either "Debug" or "End" the event.
I do not want this box to pop up. If the user selects cancel, I would like
for the "RunCommand acCmdPrint" to stop, the preview to close, and it return
back to the form from which the printing request was invoked.
Can anyone help? I simply want the report to print. I don't care about the
preview.
Respectfully,
James Bennett
can select one of several reports to print by selecting various buttons.
Each button runs an "Event Procedure" so that the reports are filtered so
that only the active record is printed. The commands used (for one of the
buttons) are as follows:
Private Sub PrintDeliveryRpt_Click()
Dim strWhere As String
If Me.Dirty Then 'Save any edits.
Me.Dirty = False
End If
If Me.NewRecord Then 'Check there is a record to print
MsgBox "Select a record to print"
Else
strWhere = "[CUSTID] = " & Me.[CUSTID]
DoCmd.OpenReport "DeliveryQuestionReport", acViewPreview, , strWhere
End If
End Sub
These commands open the print preview. The user can then select the "Print"
icon to actually print the document.
Here's the question: What do I need to add/change/modify etc. to the
commands above so that the print dialog is automatically invoked, and that
once the user either selects "print" or "cancel" the preview is closed. Not
knowing what to do, I started trying differnt things to attempt to accomplish
this task. I
tried modifying the "Else" condition by adding the "RunCommand acCmdPrint"
and the "RunCommand acCmdClose" as follows:
Else
strWhere = "[CUSTID] = " & Me.[CUSTID]
DoCmd.OpenReport "QuoteOutputReport", acViewPreview, , strWhere
RunCommand acCmdPrint
RunCommand acCmdClose
End If
This works as long as the user selects "Print" once the print dialog box
opens. The report prints and the preview closes. However, if the user
decides to "Cancel" the printing, it gives an error and prompts the user to
either "Debug" or "End" the event.
I do not want this box to pop up. If the user selects cancel, I would like
for the "RunCommand acCmdPrint" to stop, the preview to close, and it return
back to the form from which the printing request was invoked.
Can anyone help? I simply want the report to print. I don't care about the
preview.
Respectfully,
James Bennett