user52212
user52212

Reputation: 603

What causes VB6 "Run-Time Error '5': Invalid Procedure Call or Argument"

In VB6, users occasionally receive this error and I am unable to reproduce it.

Run-Time Error '5': Invalid Procedure Call or Argument

I am referencing the "MSWord 10 Object Library" and sometimes this error occurs at some point after the application has opened MSWord 2002. However, this app has referenced the MSWord 10 Object Library for years, and this error just started occurring in the last few months.

The code is shelling the app using the following:

Dim app As Word.Application = GetObject("", "Word.Application")

I am assuming I have introduced a bug somewhere, but no idea what might be causing it. The error does not occur very often and cannot be reproduced by a user when I am standing there. The error forces the app to totally shut down.

Users are running Windows XP. The user reporting the issue the most is running the app thru Citrix. There are 350 total users, about 100 use the app thru Citrix.

Any ideas on how fix the error?

Upvotes: 6

Views: 59742

Answers (3)

murspieg
murspieg

Reputation: 154

We experienced this error in a large project. In our case, the cause turned out to be set focus on an object which at the time was not visible. [Tho not the case here, I'm adding because this posting contains a lot of potential causes for Error 5.]

Upvotes: 0

jasonk
jasonk

Reputation: 1570

It may be a "speed" issue in which the user is launching Word/your form multiple times and tripping a modal display error (http://support.microsoft.com/kb/242347). e.g. Are you shelling the app or displaying it in a container window? Is it possible they are getting impatient and clicking the button/more than once? Try clicking the button more than once quickly or setting focus, hitting enter repeatedly.

If that's the case you will either need to handle/block the multiple clicks (easier) or preload Office in some way to minimize the delay while the app initializes.

Upvotes: 0

CResults
CResults

Reputation: 5105

From memory with VB6 (now using .net) this can point at the users machine being low on memory or that your code has been unable to get a handle for the word app.

If you are unable to produce the problem within Visual Studio and unsure which line in your code is causing the issue you are probably best off adding an error handler around the code that is causing the problem.

At the top of the sub that has problems put

   On Error GoTo MyErrorHandler

and then at the bottom put

   On Error Goto 0
   Exit Sub
MyErrorHandler:
   MsgBox "Error " & Err.Number & " (" & Err.Description & ") at line " & Erl

Rather than using a MsgBox as I have here consider writing down to a file instead. Also for Erl to work correctly considering numbering each of your lines.

For VB6 a great plugin is MZ tools link which will help you add the error handling and line numbers really easily

Upvotes: 5

Related Questions