Print report using vba (1 Viewer)

anb001

Registered User.
Local time
Today, 02:22
Joined
Jul 5, 2004
Messages
197
Currently when I print a report (the specific data for the report is chosen from a combo) by a click on a button, the report opens (preview), prints and close again. I use this code for doing so:

Code:
Private Sub cmdPrint_Click()

If Me.cboSelectDate <> 0 Then
    DoCmd.OpenReport "rptSJAView", acViewPreview
    DoCmd.PrintOut
    DoCmd.Close acReport, "rpSJAView", acSaveNo
Else
    MsgBox ("Please select a date.")
End If

End Sub

I would like to add two things:

1. Can I alter the code, so it just prints, without previewing.
2. If I add a textbox, where user types number of copies to be printed, can that be added as will in the code?

Thanks.

/Anders
 

bob fitz

AWF VIP
Local time
Today, 01:22
Joined
May 23, 2011
Messages
4,731
This is untested but try:

Private Sub cmdPrint_Click()
Dim i as Integer

If Me.cboSelectDate <> 0 Then
Do Until i = Nz(Me.NameOfTextbox, 1)
DoCmd.OpenReport "rptSJAView" 'This will just print it
i = i + 1
Loop
Else
MsgBox ("Please select a date.")
End If

End Sub

You wll need to change NameOfTextbox
 

anb001

Registered User.
Local time
Today, 02:22
Joined
Jul 5, 2004
Messages
197
Bob,

Thanks, I found That I use below, which works nicely:

Code:
DoCmd.SelectObject acReport, "ReportName", True
DoCmd.PrintOut acPrintAll, , , ,Me.TextBox
 

Users who are viewing this thread

Top Bottom