Selecting printer in Access 2007 Runtime

G

ggregg

I have an Access 2007 program with several reports that need to be directed
to different printers.
I find the correct DeviceName for the report from a table then I use the
command:
"Set Application.Printer = Application.Printers.DeviceName"
There are about a dozen users using a Runtime for this program.
It works great for everyone except one user.
When he tries to print the report, it gives the message:
"Invalid Procedure Call or Argument"
His printers are all set up the same as everyone else.
Is there something else I need to check?
Or does anyone have an idea why his would be different?
Thank you
 
T

Tom van Stiphout

On Thu, 22 Apr 2010 20:22:01 -0700, ggregg

I am surprised your code even compiles. Yet it does on my machine as
well. Reason: DeviceName is not a property of the Printers collection.
I will run this by my fellow MVPs but I think the reason it compiles
is because of default properties. My guess is that your RHS expression
somehow is equivalent to:
Application.Printers.Item(0)

Anyway, I would rewrite the code to explicitly select the printer
given by your table:
dim strPrinter as string
strPrinter = DLookup("myPrinter", "myTable", "myWhereClause")
dim prn as Printer
dim blnPrinterSet as Boolean
for each prn in Application.Printers
if prn.DeviceName = strPrinter then
Set Application.Printer = prn
blnPrinterSet = True
exit for
end if
next prn
if not blnPrinterSet then MsgBox "Alas, no printer found",vbCritical

-Tom.
Microsoft Access MVP
 
G

ggregg

Hi again,
The code you provided works great when using the full Access 2007 program,
but it doesn't work when I use the runtime.
Any ideas?
Thanks again
 
G

ggregg

I was able to get the reports to print on the correct printer by using your
code and calling it in this way. There were problems if I didn't reset the
default printer.
____________

Dim strPrinterName As String
Dim strDefaultPrinter As String
Dim tmpPrinterName as String

strDefaultPrinter = Application.Printer.DeviceName
strPrinterName = DLookup("myPrinter", "myTable", "myWhereClause")
Call SetSpecificPrinter(strPrinterName)
DoCmd.OpenReport "myReport"
Call SetSpecificPrinter(strDefaultPrinter)
_________

Sub SetSpecificPrinter(tmpPrinterName)
Dim prn As Printer
Dim blnPrinterSet As Boolean
For Each prn In Application.Printers
If prn.DeviceName = tmpPrinterName Then
Set Application.Printer = prn
blnPrinterSet = True
Exit For
End If
Next prn

If Not blnPrinterSet Then MsgBox "Alas, no printer found", vbCritical

End Sub

Thanks for the help
 
A

antmissile

请教----------------------如何在本社区å‘表文章?请回å¤
 

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