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. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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 | |
|
|