Invalid procedure call or argument when setting the Printer object

I have a VB6 application that gives error 5 “Invalid procedure call or argument” when the program tries to install the “Printer” object on a specific printer from the “Printers” collection. The printer in question is a kind of copier / printer that works through a print server. An error occurred while setting the Printer object to other printers defined in the collection. Any ideas that might cause error 5 in this case? I'm not sure what exactly happens when using the "Install Printer = x" instruction in VB6 - is it trying to interact with the actual printer driver at this point? Is it possible that for some reason the driver is not recognized by the VB6 Printer as a valid printer, which leads to an "invalid argument" error?

+3
source share
5 answers

"Invalid call or procedure argument" refers to a VB 5 runtime error.

I suspect the error 5 you see is a Win32 error code, which means "Access is denied."

Apparently, VB runtime errors are different from Win32 errors - I suspect that this is due to VB roots preceding even MS-DOS: http://blogs.msdn.com/ericlippert/archive/2004/09/09/227461.aspx . I'm not sure how you should determine which interpretation to use when

+3
source

Do you use code like this to install it correctly? Not just trying to set it line by line?

   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 

, . . , .

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

MS Access 2007 VBA, .

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

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

, - .

+1

, . , . "S", " ".

, :

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

5

:

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

+1
source

You can take a look at the following page:

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

When printing in VB6, I always use this dialog box instead of the usual dialog box that comes with VB6. It is much more reliable.

0
source

Source: https://habr.com/ru/post/1706232/


All Articles