tags:

views:

316

answers:

2

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.

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

+1  A: 

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

CResults
+1 Put in the error handlers and put in the line numbers, find out which line is throwing the error, and then you'll be much better placed to figure out why it is happening.
MarkJ
A: 

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.

jasonk
The code is shelling the app using the following:Dim app As Word.Application = GetObject("", "Word.Application")Actually 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