Question

I have a VB6 application that is giving an error 5, "Invalid procedure call or argument" when the program attempts to set the Printer object to a specific printer from the Printers collection. The printer in question is some sort of copier/printer running through a print server. The error doesn't occur when setting the Printer object to other printers defined in the collection. Any ideas what might be causing the error 5 in this circumstance? I'm not sure what exactly happens when using the "Set Printer = x" statement in VB6 - is it attempting to interface with the actual printer driver at that point? Is it possible that the driver isn't recognized as a valid printer by the VB6 Printer object for some reason, resulting in the "invalid argument" error?

Was it helpful?

Solution

The "Invalid procedure call or argument" is for a VB runtime error 5.

I suspect that the error 5 you're seeing is the Win32 error code, which means "Access is denied".

Apparently VB runtime errors differ from Win32 errors - I suspect that it has to do with the roots of VB predating even MS-DOS: http://blogs.msdn.com/ericlippert/archive/2004/09/09/227461.aspx. I'm not sure how you're supposed to determine which interpretation to use when

OTHER TIPS

You are using code like this to set it correct? Not just trying to set it by a string?

   Dim strDeviceName As String
   Dim prnCurrent    As Printer

   For Each prnCurrent In Printers

      If UCase$(prnCurrent.DeviceName) = strDeviceName Then

         Set Printer = prnCurrent

         Exit For

      End If

   Next prnCurrent 

In order to stop changing the default printer you run this code before you set the printer. Then you won't have to set the default printer back. This also makes your printer selection unique to your program which is what most people want.

' deassociate printer object from default system printer
Printer.TrackDefault = False

I solved this problem in MS Access 2007 VBA by including the server name along with the printer name.

Application.Printer = Application.Printers("\\servername\printername")

instead of

Application.Printer = Application.Printers("printername")

Hope this helps someone else.

I was getting this error and after a couple of hours of frustration found my answer. It was a case sensitive issue. I had a Capital "S" when I should have had a lower case "s".

So when the code looked like this:

XeroxReport = "\\Share\Red Xerox 430"
Set Application.Printer = Application.Printers(XeroxReport)

I would get error 5

But when I changed it to:

XeroxReport = "\\share\Red Xerox 430"
Set Application.Printer = Application.Printers(XeroxReport)

presto it worked

You may want to take a look at the following page:

http://support.microsoft.com/kb/322710

Whenever printing in VB6 I always use this dialog box instead of the common dialog box that comes with VB6. It is a lot more reliable.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top