andytaylor
New member
- Local time
- Today, 04:44
- Joined
- May 3, 2010
- Messages
- 3
SHORT VERSION OF MY QUESTION:
I have a document, titled "DocumentThatOpensThenCloses.doc", that does exactly what I want it to do. It opens and then closes itself, but leaves all other Word documents open. The code is as follows:
Private Sub Document_Open()
ActiveDocument.Close
End Sub
Private Sub Document_Close()
ActiveWindow.Close
End Sub
However, if I create a command button on a form in Access that opens the document, it will open the document, and then close the document, and leave any other Word documents open that were already open. The problem is that it leaves a separate instance of Word open. Unfortunately, Application.Quit is not an option for me because, when I eventually implement this, I will have to have other Word documents open.
The code in Access that I'm using to open my document is as follows:
Private Sub Command4_Click()
On Error GoTo Err_Command4_Click
Dim oApp As Object
Set oApp = CreateObject("Word.Application")
oApp.Visible = True
Exit_Command4_Click:
Exit Sub
Err_Command4_Click:
MsgBox Err.Description
Resume Exit_Command4_Click
(Incidentally, I didn't write this code, it's just the code that was created from the Command Button wizard). Under properties for this command button, I set "DocumentThatOpensThenCloses.doc" as the hyperlink.
A LITTLE MORE EXPLANATION:
I have a series of documents that I am mail-merging from access. Basically, I have set up several Word documents as mail merge documents, and then I have command buttons in Access that open the documents. Inside those documents, I have a macro that executes the mail merge, and creates a new document with the data in it. My goal is to then close the original mail merge document, which I am able to do, but the problem is that every time I create a new mail merge, I am left with another empty Word window with no document in it.
I am using Access 2003 SP3 and Word 2003 SP3.
I have a document, titled "DocumentThatOpensThenCloses.doc", that does exactly what I want it to do. It opens and then closes itself, but leaves all other Word documents open. The code is as follows:
Private Sub Document_Open()
ActiveDocument.Close
End Sub
Private Sub Document_Close()
ActiveWindow.Close
End Sub
However, if I create a command button on a form in Access that opens the document, it will open the document, and then close the document, and leave any other Word documents open that were already open. The problem is that it leaves a separate instance of Word open. Unfortunately, Application.Quit is not an option for me because, when I eventually implement this, I will have to have other Word documents open.
The code in Access that I'm using to open my document is as follows:
Private Sub Command4_Click()
On Error GoTo Err_Command4_Click
Dim oApp As Object
Set oApp = CreateObject("Word.Application")
oApp.Visible = True
Exit_Command4_Click:
Exit Sub
Err_Command4_Click:
MsgBox Err.Description
Resume Exit_Command4_Click
(Incidentally, I didn't write this code, it's just the code that was created from the Command Button wizard). Under properties for this command button, I set "DocumentThatOpensThenCloses.doc" as the hyperlink.
A LITTLE MORE EXPLANATION:
I have a series of documents that I am mail-merging from access. Basically, I have set up several Word documents as mail merge documents, and then I have command buttons in Access that open the documents. Inside those documents, I have a macro that executes the mail merge, and creates a new document with the data in it. My goal is to then close the original mail merge document, which I am able to do, but the problem is that every time I create a new mail merge, I am left with another empty Word window with no document in it.
I am using Access 2003 SP3 and Word 2003 SP3.