Initializing the workstation printer for a report.

P

PJ@NASA

Hellow Everyone!

My application makes visitor badges and is used on several different
computer workstations. The badge is just an Access report, and is printed
to the local badge printer.

Problem is that each workstation has a slightly different printer
configuration and I can't make the badge printer the default printer because
the workstations are also used for other work. The sympton is that every
time I put a new version out, Access has to be told (the first time) what
printer to use to print the badge. My users are not so computer literate, so
I have to go around and 'fix' each workstation every time I release a new
version. I'm working on trying to automate something that will 'initialize'
each workstion to use the correct printer.

The code I'm currently working on cycles through the printers collection
until it finds the correct printer. Then it opens the badge report in disign
view (hidden) and aims the reports printer properties the local badge
printer. I've make sure each printer contains the string "DTC5" so this
routine can identify it. I have three different badges I'm trying to
initialize.

Dim i As Integer
Dim prt As Printer
Dim Rpt As Report
Dim strReportName As String

' Cycle through the printers installed on the machine
For Each prt In Application.Printers
If InStr(1, prt.DeviceName, "DTC5", vbTextCompare) > 0 Then 'found the
badge printer
For i = 1 To 3
Select Case i
Case 1
strReportName = "Rpt_Walk_Up_Badge"
Case 2
strReportName = "Rpt_OldBadge"
Case 3
strReportName = "Rpt_FE_Backdrop_Badge"
End Select

DoCmd.OpenReport strReportName, acDesign, , , acHidden 'open
report
Set Rpt = Reports(strReportName) 'create report object
Rpt.Printer = prt 'set printer
Rpt.PrtDevMode = prt.DriverName
Rpt.PrtDevNames = prt.DeviceName
DoCmd.Close , strReportName, acSaveYes 'close and save
Next i
End If
Next

Set Rpt = Nothing

Problem with this code is that it just doesn't work. The DoCmd.Close
doesn't close the report and the settings are not saved.

Any advice appreciated.

PJ
 
A

Albert D. Kallal

What version of ms-access?

Why not just have a "setting" in your application (a combo box that "lists"
the printers, and you set which one is for the badge.

Then, in code you go:

save current (default) printer.

Change default printer to your badge printer.
Print badge

Change printer back.....

The above means you NEVER have to open up a report in design mode, and thus
you can even deploy your application in runtime mode. In fact you should
usually deploy as a mde, and thus user can't get into design mode.

You need access 2002 or later, since that's when the printer object was
introduct introdued...

The code for the above lodgic is:

So, to save/switch, you can use:

dim strDefaultPrinter as string

' get current default printer.
strDefaultPrinter = Application.Printer.DeviceName

' switch to printer of your choice:

Set Application.Printer = Application.Printers("HP LaserJet Series II")

do whatever.

Swtich back.

Set Application.Printer = Application.Printers(strDefaultPrinter)

So, for your report, always leave it as the default printer....and don't
have the report change the printer...simply change the current printer in
code, print...and then switch back.....
 

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