Prev: Zoom level in Access 2010
Next: thankyou
From: ggregg on 22 Apr 2010 23:22 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
From: Tom van Stiphout on 23 Apr 2010 01:06 On Thu, 22 Apr 2010 20:22:01 -0700, ggregg <ggregg(a)discussions.microsoft.com> 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
From: ggregg on 23 Apr 2010 12:02 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 > <ggregg(a)discussions.microsoft.com> 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 > . >
From: ggregg on 26 Apr 2010 14:31 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 > <ggregg(a)discussions.microsoft.com> 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 > . >
From: ggregg on 12 May 2010 16:36
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 |