“无效的过程调用或参数” 设置打印机对象时

发布于 2024-07-16 07:04:09 字数 285 浏览 10 评论 0原文

我有一个 VB6 应用程序,当程序尝试将 Printer 对象设置为 Printers 集合中的特定打印机时,出现错误 5“无效的过程调用或参数”。 有问题的打印机是通过打印服务器运行的某种复印机/打印机。 将打印机对象设置为集合中定义的其他打印机时,不会发生该错误。 有什么想法可能会导致这种情况下的错误 5 吗? 我不确定在 VB6 中使用“Set Printer = x”语句时到底会发生什么 - 它是否尝试与实际的打印机驱动程序进行交互? 是否有可能由于某种原因驱动程序未被 VB6 打印机对象识别为有效打印机,从而导致“无效参数”错误?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

秋心╮凉 2024-07-23 07:04:09

“无效的过程调用或参数”是针对 VB 运行时错误 5 的。

我怀疑您看到的错误 5 是 Win32 错误代码,这意味着“访问被拒绝”。

显然 VB 运行时错误与 Win32 错误不同 - 我怀疑它与甚至早于 MS-DOS 的 VB 根源有关: http://blogs.msdn.com/ericlippert/archive/2004/09/09/227461.aspx。 我不确定您应该如何确定何时使用哪种解释

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

挽清梦 2024-07-23 07:04:09

您正在使用这样的代码来将其设置正确吗?
不只是试图通过字符串设置它?

   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

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
给不了的爱 2024-07-23 07:04:09

我在 MS Access 2007 VBA 中通过包含服务器名称和打印机名称解决了这个问题。

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

而不是

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

希望这对其他人有帮助。

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.

一抹微笑 2024-07-23 07:04:09

我遇到了这个错误,经过几个小时的沮丧后找到了我的答案。 这是一个区分大小写的问题。 当我应该使用小写“s”时,我却使用了大写“S”。

所以当代码看起来像这样时:

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

我会得到错误 5

但是当我将其更改为:

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

presto 时它就起作用了

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

阳光的暖冬 2024-07-23 07:04:09

您可能需要查看以下页面:

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

每当在 VB6 中打印时,我总是使用此对话框而不是 VB6 附带的通用对话框。 它更可靠。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文