A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » General Discussion
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Selecting printer in Access 2007 Runtime



 
 
Thread Tools Display Modes
  #1  
Old April 23rd, 2010, 04:22 AM posted to microsoft.public.access
ggregg
external usenet poster
 
Posts: 43
Default Selecting printer in Access 2007 Runtime

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
  #2  
Old April 23rd, 2010, 06:06 AM posted to microsoft.public.access
Tom van Stiphout[_2_]
external usenet poster
 
Posts: 1,653
Default Selecting printer in Access 2007 Runtime

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

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


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

  #3  
Old April 23rd, 2010, 05:02 PM posted to microsoft.public.access
ggregg
external usenet poster
 
Posts: 43
Default Selecting printer in Access 2007 Runtime

My initial test using your code works.
Thank you very much

"Tom van Stiphout" wrote:

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

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


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

.

  #4  
Old April 26th, 2010, 07:31 PM posted to microsoft.public.access
ggregg
external usenet poster
 
Posts: 43
Default Selecting printer in Access 2007 Runtime

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

"Tom van Stiphout" wrote:

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

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


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

.

  #5  
Old May 12th, 2010, 09:36 PM posted to microsoft.public.access
ggregg
external usenet poster
 
Posts: 43
Default Selecting printer in Access 2007 Runtime

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
  #6  
Old May 24th, 2010, 01:16 AM posted to microsoft.public.access
antmissile
external usenet poster
 
Posts: 1
Default Selecting printer in Access 2007 Runtime

请教----------------------如何在本社区发表文*?请回复

"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


 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 03:36 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright 2004-2024 OfficeFrustration.
The comments are property of their posters.