Results 1 to 10 of 10
  1. #1
    n2cheval
    Guest

    Access to Word Automation (97/2000)

    I seem to be having a problem re-referencing the word object after closing a document. eg, using access automation, create a word object, open a document from a template, fill with data, close and save document, release object reference, create another reference and try again with a different template and data.
    On the second one, the screen is blank and it seems to work, except when you try to goto bookmarks.
    I also get it with excel so I think its something that I doing (or not doing right.)

  2. #2
    Gold Lounger
    Join Date
    Jun 2001
    Location
    Crystal Beach, FL, Florida, USA
    Posts
    3,436
    Thanks
    1
    Thanked 34 Times in 34 Posts

    Re: Access to Word Automation (97/2000)

    >>On the second one, the screen is blank and it seems to work, except when you try to goto bookmarks.<<

    I'm not sure I understand my what you mean by this. Given that the screen is blank (meaning Word didn't create a new document using your template), then why does it "seem to work"? Maybe you could post an abbreviated version of your code, the one that shows how you create/close the word reference and open/close the new document.
    Mark Liquorman
    See my website for Tips & Downloads and for my Liquorman Utilities.

  3. #3
    n2cheval
    Guest

    Re: Access to Word Automation (97/2000)

    I found in another post a link to a MS doco on how it should be done. Mine was like as follows:

    Dim appWord As Word.Application
    Dim docs As Word.Documents
    Dim docTemp As Word.Document

    On Error Resume Next
    Set appWord = GetObject(, "Word.Application")
    If Err.Number = 429 Then
    'Word is not running; creating a Word object
    Set appWord = CreateObject("Word.Application")
    Err.Clear
    End If

    Set docs = appWord.Documents
    docs.Add Template:="MyTemplate"

    Hope this helps to explain better.

  4. #4
    Gold Lounger
    Join Date
    Jun 2001
    Location
    Crystal Beach, FL, Florida, USA
    Posts
    3,436
    Thanks
    1
    Thanked 34 Times in 34 Posts

    Re: Access to Word Automation (97/2000)

    What you have seems to parallel the code I use. But I still don't understand where you are having the problem. Are you closing the first document and starting another, or are you closing the word object then starting another?
    Mark Liquorman
    See my website for Tips & Downloads and for my Liquorman Utilities.

  5. #5
    n2cheval
    Guest

    Re: Access to Word Automation (97/2000)

    I am both closing the document and I thought, closing the object as well and then starting another of both.

    What I haven't shown, is how I close the app and release the object. Maybe that's where the problem is?

    AppWord.Application.Quit
    Set AppWord = Nothing

    Well, when I run very similar code again, the screen displays nothing yet the data insertion is fine. It's not until I close Access does it seem to release Word (or Excel when send data to it). Then I can run one again and yet on the second try, it goes dark. The Word or Excel window elements (toolbars, scroll bars) are fine, yet not the display inside. It hasn't been a problem until I needed to create multiple documents and the users wanted to see what was happening.

  6. #6
    Gold Lounger
    Join Date
    Jun 2001
    Location
    Crystal Beach, FL, Florida, USA
    Posts
    3,436
    Thanks
    1
    Thanked 34 Times in 34 Posts

    Re: Access to Word Automation (97/2000)

    You still left out a chunk of code that explains what you are doing. You have created a word document based on a template. Then I assume you filled all the bookmarks (I don't need exact code for this). But then what? Can user modify the new document? Are your printing this document? Are you saving it? If yes, then how?

    Also, when you re-open Word, is it within the same event code (that is, without leaving the event) or is it just another time in that event (that is, the next time you clicked the Print button on your form).
    Mark Liquorman
    See my website for Tips & Downloads and for my Liquorman Utilities.

  7. #7
    n2cheval
    Guest

    Re: Access to Word Automation (97/2000)

    In the simple cases I just fill in the book marks and then use the wdApp.SaveAs command. Then Set WdApp = nothing. So I thought Everything would be closed down and memory would be freed. Yet looking at the running processes, it is still running until I close down access.

    No, when I open another template it is from another function, usually in the same module though. Hmm maybe the module is keeping the work object live? usually the case where either some data setting have been changed by the use and another doc needs to be created or that two documents need to be created from two different sets of unrelated code functions. Yes I do try to reuse and componentise code as much as possible.

  8. #8
    Gold Lounger
    Join Date
    Jun 2001
    Location
    Crystal Beach, FL, Florida, USA
    Posts
    3,436
    Thanks
    1
    Thanked 34 Times in 34 Posts

    Re: Access to Word Automation (97/2000)

    The "Set WdApp=nothing" merely closes the object you created in Access that points to Word. You apparently never closed Word itself. Did you ever do a "WdApp.Quit"?
    Mark Liquorman
    See my website for Tips & Downloads and for my Liquorman Utilities.

  9. #9
    n2cheval
    Guest

    Re: Access to Word Automation (97/2000)

    yeah just before a Set wdApp = Nothing, I do a wdApp.Application.Quit

  10. #10
    Gold Lounger
    Join Date
    Jun 2001
    Location
    Crystal Beach, FL, Florida, USA
    Posts
    3,436
    Thanks
    1
    Thanked 34 Times in 34 Posts

    Re: Access to Word Automation (97/2000)

    >>, I do a wdApp.Application.Quit <<

    Just to be safe, you might want to make it:

    wdApp.Application.Quit savechanges:=wdDoNotSaveChanges
    Mark Liquorman
    See my website for Tips & Downloads and for my Liquorman Utilities.

Posting Permissions

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