0
votes

A somewhat similar question has been asked before, but the solution didn't work for me.

For instance, http://www.xtremevbtalk.com/showthread.php?t=99503

Background:

I have a MS Access 2010 database. In my database I have a form with a button. I've programmed the button to open a saved word document, populated book-marked places in the document, then save-as the word document with a name that includes the time (henceforth referred to as the auto-filled document). This all works just fine.

The problem:

If a different MS word document was already open when I clicked the button, then I have trouble closing the resulting auto-filled document. This is what happens:

1) I try to "x" out of my auto-filled word document. 2) the computer tells me that "This file is in use by another application or user // (C:....\Normal.dotm)" 3) I click "ok" 4) it offers to save-as the Normal template. 5) I click "cancel" 6) I try to "x" out of the word application once more. 7) the computer prompts me: "Changes have been made that affect the global template, Normal. Do you want to save those changes?" 8) I click "Don't save" 9) the application closes.

(This only occurs for instances when a word document is already open when I click the button on the form. Otherwise it works perfectly.)

My question:

Normally, I would just shrug and live with these extra few steps, but I'm the one making the database, so I have to think about my users. (Would it mess anything up to save the normal template--step 7?)

I googled this for a while. For similar situations, some people suggested adding objApp.NormalTemplate.Saved = True (where objApp is the Word application object), but this did not work for me.

Can someone please tell me what's going on? Is there a solution?

Any help will be much appreciated.

1
can you add a link to this question: A somewhat similar question has been asked before (...)?Kazimierz Jawor
Ah, this seems to solve it: support.microsoft.com/kb/285885 Application.Quit SaveChanges:=wdDoNotSaveChangesuser3380641
And the reason for the problem is that the word application was already open and my code instructed it to open again. This link has a purer solution: databaseadvisors.com/newsletters/newsletter072002/…user3380641

1 Answers

0
votes

What you need to do is check to see if an instance of Word is already open. If it is, you might want to let your user know they need to close their Word doc.

' Handle Error In-Line
On Error Resume Next
Set objWord = GetObject(, "Word.Application")

If Err.Number = 429 Then
    'If we got an error, that means there was no Word Instance
    Set objWord = CreateObject("Word.Application")
Else
    Msgbox ("You're going to need to close any open Word docs before you can perform this function.", vbOK)
    Exit Sub
End If

'Reset Error Handler
On Error GoTo 0