I have searched several forums (and read and re-read all the books I have) for an example on how to select a printer during runtime. There are several examples in this forum alone but none do what I think would be the obvious thing.
I have two reports that need to be printed on seperate printers. One is a simple report that currently prints on the default printer. The other is the tricky one. It must print on a thermal printer to print shipping labels. The printer driver is setup and I know it works.
What I idealy would like to have a is to be able to open a form or dialogue, select the report in question and set the printer for that report only. When setting is complete, close and SAVE the settings.
I am using Access XP and have the Office Developer with runtime. Another important fact is that the reports are designed to print the moment the print button is clicked. No preview therefore the option to allow the user to click on the setup button is NOT an option. (hence why I need this done programically).
I have the following code supplied by ........
' From Access 2002 Developer's Handbook, Volume I
' by Litwin, Getz, and Gunderloy (Sybex)
For some reason the above code does not do what it says it's suppose do to. Any help would be appreciated.
Regards
I have two reports that need to be printed on seperate printers. One is a simple report that currently prints on the default printer. The other is the tricky one. It must print on a thermal printer to print shipping labels. The printer driver is setup and I know it works.
What I idealy would like to have a is to be able to open a form or dialogue, select the report in question and set the printer for that report only. When setting is complete, close and SAVE the settings.
I am using Access XP and have the Office Developer with runtime. Another important fact is that the reports are designed to print the moment the print button is clicked. No preview therefore the option to allow the user to click on the setup button is NOT an option. (hence why I need this done programically).
I have the following code supplied by ........
' From Access 2002 Developer's Handbook, Volume I
' by Litwin, Getz, and Gunderloy (Sybex)
Code:
Private Sub cmdChosen_Click()
On Error Resume Next
Dim strRptName As String
strRptName = cboObjects.Value
If chkChangeDefaultPrinter.Value Then
' The report must be set to use the default printer
' in order for this to work. Otherwise, you must open
' the report first, then set its UseDefaultPrinter
' property to True, then open it again to print it.
Set Application.Printer = Application.Printers(cboDestination.ListIndex)
DoCmd.OpenReport strRptName, View:=acViewNormal
Set Application.Printer = Nothing
Else
DoCmd.OpenReport strRptName, View:=acPreview, WindowMode:=acHidden
With Reports(strRptName)
Set .Printer = Application.Printers(cboDestination.ListIndex)
End With
DoCmd.OpenReport strRptName, View:=acViewNormal
End If
End Sub
Private Sub cmdDefault_Click()
' Print to the current location.
' You must have selected an object (obj) before you end up here!
On Error Resume Next
DoCmd.OpenReport cboObjects
Call DoCleanup
End Sub
Private Sub DoCleanup()
cboObjects.Value = vbNullString
lblCurrentDestination.Caption = vbNullString
chkUseDefault.Value = False
cboObjects.SetFocus
cmdChosen.Enabled = False
cmdDefault.Enabled = False
End Sub
Private Sub Form_Load()
' Initialize the list type, and
' fill in the list of objects.
Dim prt As Printer
cboObjects.RowSourceType = "Value List"
Call FillObjectList
For Each prt In Printers
Me.cboDestination.AddItem prt.DeviceName
Next prt
Me.cboDestination = Application.Printer.DeviceName
End Sub
Private Sub GetReportList()
Dim strOut As String
Dim objItem As AccessObject
Dim col As Object
' Clear the list before adding new items.
cboObjects.RowSource = vbNullString
For Each objItem In CurrentProject.AllReports
cboObjects.AddItem objItem.Name
Next objItem
End Sub
Private Sub cboObjects_AfterUpdate()
Dim strRptName As String
Dim strPrtName As String
Dim rpt As Report
strRptName = cboObjects.Value
DoCmd.OpenReport strRptName, View:=acPreview, WindowMode:=acHidden
With Reports(strRptName)
strPrtName = .Printer.DeviceName
chkUseDefault.Value = .UseDefaultPrinter
chkChangeDefaultPrinter.Enabled = .UseDefaultPrinter
If Not .UseDefaultPrinter Then
chkChangeDefaultPrinter.Value = False
End If
End With
lblCurrentDestination.Caption = strPrtName
DoCmd.Close acReport, strRptName
' Enable the printing buttons.
cboObjects.SetFocus
cmdChosen.Enabled = True
cmdDefault.Enabled = True
End Sub
Private Sub FillObjectList()
Call GetReportList
Call DoCleanup
End Sub
For some reason the above code does not do what it says it's suppose do to. Any help would be appreciated.
Regards