"Invalid procedure call or argument" when setting Printer object

E Brown picture E Brown · Apr 10, 2009 · Viewed 7.5k times · Source

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?

Answer

Michael Burr picture Michael Burr · Apr 10, 2009

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