Results 1 to 10 of 10
  1. #1
    5 Star Lounger
    Join Date
    Mar 2001
    Location
    New York, NY
    Posts
    922
    Thanks
    2
    Thanked 12 Times in 11 Posts

    Unspecified Error VBA (Word XP)

    I spent many hours today working on a Word template that has had significant editing over the last months. From time to time, I export all of the modules, user forms, AutoText and toolbar and import these components into a new container.. The file size usually decreases by 25% when I do that. I compile the template after importing.

    After going through this process today, an error displayed the first time I launched the template. The message said, "Automation error. Unspecified error." It occurred once, and has not appeared again, after testing 25 or 30 times. I modified the template slightly, so it was compiled again and saved. When I uploaded the template to the network, the same thing occured: once, and only once, the Automation Error message appeared, and not since.

    Is there any sense to be made from the "unspecified error" message? Debug|Compile is problem-free, and the code runs perfectly. Even when the error appears on the initial run, there is no probelm with code execution. It's a rather large template: 14 user forms, 5 code modules, 1 custom toolbar and 5 AutoText entries. The only unusual item in the template is the Date Picker on 4 of the user forms.

    Thanks,
    Richard Barrett

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Unspecified Error VBA (Word XP)

    Where does the error occur? If you have error handling throughout the code (normally a desirable feature), you might disable it temporarily to see which line of code causes the error.

  3. #3
    5 Star Lounger
    Join Date
    Mar 2001
    Location
    New York, NY
    Posts
    922
    Thanks
    2
    Thanked 12 Times in 11 Posts

    Re: Unspecified Error VBA (Word XP)

    The erros occurs at the very end; all of the code has run, the last piece of the document has falledn into place. (Depending upon the elements of the document and the totals of several sections -- calculated by the code --, one of several signature/approval blocks is added at the end of the document. This takes place exactly as expected.)

    I've now seen this a second time on my PC. As it happens, I had the code open. When the error message displays (End, Debug, Help), only End is enabled. At this point in the code, I have no error handling.

    Thanks,
    Richard

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Unspecified Error VBA (Word XP)

    You could try setting a breakpoint somewhere near the end of the code, then single step to see where the error occurs.

  5. #5
    5 Star Lounger
    Join Date
    Mar 2001
    Location
    New York, NY
    Posts
    922
    Thanks
    2
    Thanked 12 Times in 11 Posts

    Re: Unspecified Error VBA (Word XP)

    I was trying that just as you were probably writing. Every line of the code executes; the error appears on the line with End Sub.

    At the end of the code, I Unload each of the user forms that I have used. (Three are useful to me right up to the end.) As each Unload executes, the Initialize event of the related form runs. Is this to be expected? I usually use the Activate event for user forms, but occasionally I've used Initialize when I know the form might be displayed a second time, and I don't want to Activate to fire each time. Is there a hard and fast rule about Initialize/Activate?

    That doesn't appear to be the cause of the probelm at hand, but I was surprised to see this.

    Thanks,
    Richard

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Unspecified Error VBA (Word XP)

    Do you have code that refers to a property or control of a userform after you unload it? That would cause the form to be initialized again.

    Would it be acceptable to hide the userforms instead of unloading them?

  7. #7
    5 Star Lounger
    Join Date
    Mar 2001
    Location
    New York, NY
    Posts
    922
    Thanks
    2
    Thanked 12 Times in 11 Posts

    Re: Unspecified Error VBA (Word XP)

    No, the last few lines of the code are

    Unload frmA
    Unload frmB
    Unload frmC

    With a breakpoint set, Unload frmA causes the Initialize event of frmA to run. Hide is less acceptable as it tends to leave values in memory so text controls, etc. display those values the next time the template runs.

    I think I shold go through the export and import process again.

    Richard

  8. #8
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Unspecified Error VBA (Word XP)

    You could clear all controls either when you hide the form or in the UserForm_Initialize event.

  9. #9
    5 Star Lounger
    Join Date
    Mar 2001
    Location
    New York, NY
    Posts
    922
    Thanks
    2
    Thanked 12 Times in 11 Posts

    Re: Unspecified Error VBA (Word XP)

    I was just very surprised to see the Initialize code fire at Unload. I suppose I could set a variable just before Unload, for example bUnload = True. The top of the initialize code could be If bUnload = True Then Exit Sub. I could perhaps put most of the code in the Activiate event; which hopefully doesn't run, too, at Unload.

    Did you realize that Unload caused the Initialize event to fire?

    The "Unspecified error" problem seems to be with this particular version of the template as it's been assembled/compiled/saved on this PC. The template has been constantly modified -- made bigger and more robust -- over the last two years. Despite the fact that I export/import often, the code is far more comlicated than it would be if I were starting over. That has not been an option from a time/money perspective.

    Richard

  10. #10
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Unspecified Error VBA (Word XP)

    It is not normal that unloading a userform causes the Initialize event to run again; there must be something in your code that causes it.

    The ideas you mention are worth a try - since you cannot redesign the template from scratch, anything that makes it work is fine.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •