PrintMode

B

Brandon Schultz

I am using the example out the Northwinds Sample DB that uses the following
procedure

Sub PrintReports(PrintMode As Integer)
On Error GoTo Err_Preview_Click

Dim stDocName As String
Dim ReportSelection As String

ReportSelection = Me.cboLabelFormat

If ReportSelection = "JDC Format" Then
stDocName = "rptLabelsFormatJDC"
DoCmd.OpenReport stDocName, PrintMode
End If

Exit Sub

The code attached to my Preview button and my Print button looks like this:

Private Sub cmdPreview_Click()

PrintReports acPreview

End Sub

Private Sub cmdPrint_Click()

PrintReports acNormal

End Sub

My question is this; what code do I need to write to make use of a text box
on my form for number of copies. I realize that doing something like:
DoCmd.OpenReport stDocName, acViewPreview
DoCmd.PrintOut , , , , Me.txtQuantity
DoCmd.Close acReport, stDocName

would work but stDocName is in a different procedure and I have a lot of
report selections.

Thanks in advance for any guidance.

Brandon Schultz
 
H

Hal

Which version are you using?
If you are using ACC2002 or higher you could use the Printer Object - a
member of the Printers Collection - here is an example of code behind my
Print Preview button:
HTH

Hal

******* Code Begin **************

Private Sub cmdPreviewReport_Click()
Dim strDocName As String
Dim avarSItem() As String
Dim strName As String
Dim blnIsValidPrinter As Boolean
Dim prt As Printer

On Error GoTo Err_cmdPreviewReport_Click

' Check for Null value in cboPrinter control
' to validate that the user has selected a printer.
If IsNull(Me!cboPrinter.Value) Then
MsgBox Prompt:="Select a valid printer from the list before clicking
Preview."
' Reset cboPrinter back to the default printer and exit.
Me!cboPrinter = Application.Printer.DeviceName
Exit Sub
Else
' Set variable to selected printer.
strName = Me!cboPrinter.Value
End If

' Initialize the valid printer flag.
blnIsValidPrinter = False

' Check to see if the value in cboPrinter matches an installed printer.
For Each prt In Application.Printers
If prt.DeviceName = strName Then
blnIsValidPrinter = True
End If
Next

' Check the valid printer flag.
If Not blnIsValidPrinter Then
MsgBox "Select a valid printer from the list before clicking
Preview."
' Reset cboPrinter to default printer and exit.
Me!cboPrinter = Application.Printer.DeviceName
Exit Sub
End If

' Grab the printer object for the selected printer.
Set prt = Application.Printers(Me!cboPrinter.Value)

If IsNull(Me!txtCopies.Value) Then
MsgBox Prompt:="Enter number of copies you wish " & _
"to print before clicking Preview."
' Reset txtCopies back to the default and exit.
Me!txtCopies.SetFocus
'Printer.Copies
Exit Sub
Else
' Read user-specified settings (Number of copies).
prt.Copies = Me!txtCopies
End If

Set ctlS = Me!lstSelected
strDocName = "rptBillingSummaryByMonth"

If ctlS.ListCount > 0 Then
avarSItem = Split(ctlS.RowSource, ";")
Me!txtCriteria = Join(avarSItem, " OR ")

With DoCmd
.OpenReport strDocName, acViewPreview

.RunCommand acCmdZoom75
.Maximize
End With
' Set the report's printer to the modified printer object.
Reports(strDocName).Printer = prt
Else
MsgBox "There are no items to Print." & vbNewLine & _
"Please select at least one item, from the Available Items List.", _
vbOKOnly + vbExclamation, "No items selected"
Exit Sub
End If

Erase avarSItem

Exit_cmdPreviewReport_Click:
Exit Sub

Err_cmdPreviewReport_Click:
Call LogError(Err.Number, Err.Description, _
"frmPrintSelectQtr_cmdPreviewReport_Click")
Resume Exit_cmdPreviewReport_Click

End Sub 'cmdPreviewReport_Click()



********* Code End ************
 
N

Newbie

I am not quite sure how your project is laid out but can you not make the
stDocName a public variable and have another public variable called mCopies

Open a new modules and type the following

Public stDocName as string
Public mCopies as string

By doing this stDocName and mCopies will be available for all procedures
once they have been set .. . something like

In the AfterUpdate event of listbox
stDocName = me.listbox.value

in the click event of button
DoCmd.OpenReport stDocName, acViewPreview
DoCmd.PrintOut , , , , Me.txtQuantity
DoCmd.Close acReport, stDocName


HTH

Al
 

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