Solved

How do I clear variables from Word

Posted on 2001-06-12
5
157 Views
Last Modified: 2010-05-02
Ok

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\GPOA.dot"
 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
    GetDate
    ExpireDate
    SubExpireDate
    SubFindReplaceName
    SubFindReplaceSSN
    SubFindReplaceState
    SubFindReplaceGPOAAgent
    SubFindReplaceDate
End With
 'Close Word
 wrdGPOA.Quit
 '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 document...it won't go...no 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

thanks!



0
Comment
Question by:phred_the_cat
[X]
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
5 Comments
 
LVL 38

Expert Comment

by:PaulHews
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


http://support.microsoft.com/support/kb/articles/Q189/6/18.ASP 
0
 
LVL 38

Accepted Solution

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

CAUSE
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.

0
 
LVL 2

Expert Comment

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

Chandu
0
 

Author Comment

by:phred_the_cat
ID: 6184543
Thanks man...now I just gotta figure out how to fix it
0
 
LVL 38

Expert Comment

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

Unqualified.

Selection.Paste

Qualified (corrected)

wrdGPOA.Selection.Paste


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.
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Suggested Courses
Course of the Month7 days, 17 hours left to enroll

617 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