Printing from an "Event Procedure".

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
 
S

strive4peace

Hi James,

the default is to print -- but you are specifying Preview in one of the
arguments. Remove acViewPreview to send it immediately to the printer

DoCmd.OpenReport "QuoteOutputReport", , , strWhere

what I like to do is put an option box on the form and give the user a
choice to print or preview -- then, depending on what they choose, I
modify the second argument (view)

acViewPreview = 2
acViewNormal = 0


Warm Regards,
Crystal

remote programming and training

Access Basics
8-part free tutorial that covers essentials in Access
http://www.AccessMVP.com/strive4peace

*
:) have an awesome day :)
*
 
J

J.Bennett

Thanks!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! That works! I really don't want the
option to preview as all the information is displayed on the form. The print
options simply puts all the information on the hard copy form as required for
the manufacturer. Thanks a million!

James Bennett


strive4peace said:
Hi James,

the default is to print -- but you are specifying Preview in one of the
arguments. Remove acViewPreview to send it immediately to the printer

DoCmd.OpenReport "QuoteOutputReport", , , strWhere

what I like to do is put an option box on the form and give the user a
choice to print or preview -- then, depending on what they choose, I
modify the second argument (view)

acViewPreview = 2
acViewNormal = 0


Warm Regards,
Crystal

remote programming and training

Access Basics
8-part free tutorial that covers essentials in Access
http://www.AccessMVP.com/strive4peace

*
:) have an awesome day :)
*




J.Bennett said:
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
 
S

strive4peace

you're welcome, James ;) happy to help

Warm Regards,
Crystal

remote programming and training

Access Basics
8-part free tutorial that covers essentials in Access
http://www.AccessMVP.com/strive4peace

*
:) have an awesome day :)
*




J.Bennett said:
Thanks!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! That works! I really don't want the
option to preview as all the information is displayed on the form. The print
options simply puts all the information on the hard copy form as required for
the manufacturer. Thanks a million!

James Bennett


strive4peace said:
Hi James,

the default is to print -- but you are specifying Preview in one of the
arguments. Remove acViewPreview to send it immediately to the printer

DoCmd.OpenReport "QuoteOutputReport", , , strWhere

what I like to do is put an option box on the form and give the user a
choice to print or preview -- then, depending on what they choose, I
modify the second argument (view)

acViewPreview = 2
acViewNormal = 0


Warm Regards,
Crystal

remote programming and training

Access Basics
8-part free tutorial that covers essentials in Access
http://www.AccessMVP.com/strive4peace

*
:) have an awesome day :)
*




J.Bennett said:
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
 

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


Top