How do I clear variables from Word

Posted on 2001-06-12
Last Modified: 2010-05-02

Here is the code I'm using

Main Module (all the variable are here):

Sub Main()
Dim oform As frmEZDocs
Set oform = New frmEZDocs
    oform.Show vbModal
Set oform = Nothing
End Sub

Form "EZDocs" (Main Form)
collects most of the variables, and launches the various subroutines...for example, a power of attorney routine below:

'This is the main subroutine for this form
Private Sub cmdGPOA_Click()
 On Error Resume Next
Dim wrdGPOA As Word.Application
Dim strTemplate As String
strTemplate = "C:\EZDocs\templates\"
 Set wrdGPOA = GetObject(, "Word.Application")
 If wrdGPOA Is Nothing Then
   Set wrdGPOA = CreateObject("Word.Application")
 End If
 With wrdGPOA
    .Documents.Add (strTemplate)
    wrdGPOA.Visible = True
End With
 'Close Word
 'Release resources
Set wrdGPOA = Nothing
End Sub

I run this from one of my forms, and it takes information from forms to automate a power of attornet.  It runs fine, but after I make the first document, when I attempt to launch a second won't error...and something is happening in background, but no product output.  Is there some way to put a "reset" button on the form(s) so that all variables are reset, without haveing to exit and reload the program


Question by:phred_the_cat
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
LVL 38

Expert Comment

ID: 6182222
Could be... usually you will get an error with this problem...

Unqualified use of an internal Word object causes problems.  Qualifying the object fixes it.

This link documents the problem 
LVL 38

Accepted Solution

PaulHews earned 50 total points
ID: 6182230
The reason I suspect this:

Visual Basic has established a reference to Word due to a line of code that calls a Word object, method, or property without qualifying it with a Word object variable. Visual Basic does not release this reference until you end the program. This errant reference interferes with automation code when the code is run more than once.


Expert Comment

ID: 6183377
PaulHews is absolutely right.  I had same problem with
Excel, I fixed after seeing Paul's comments.


Author Comment

ID: 6184543
Thanks I just gotta figure out how to fix it
LVL 38

Expert Comment

ID: 6186053
Well, if it is the problem I mentioned earlier, hunt through all the code looking for unqualified Word objects.  eg.



Qualified (corrected)


Any internal Word object (Range, Selection, ActiveDocument, etc.) must be prefaced in this way.  

I am still not sure that this is the problem.  If it isn't let me know and I'll get CS to delete the question and refund your points so that you can ask it again.

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question