Printing

J

J.Bennett

I have a database used for selling portable storage buildings. The Database
has three main forms. From one of the forms, the user can select a several
reports to print by selecting various buttons. Each of these 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. I
tried modifying the "Else" condition 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?

Respectfully,
James Bennett
 

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

Top