bradmaunsell
Programmer
How can I detect a close event in MS Word document that is opened from MS Access?
I have an MS Access form displaying a name and address (Northwind) having a button to open a new MS Word doc and head it up with a name and address displayed on the form.
Once the doc is opened with the header info inserted, I want the user to be able type whatever they want in the Word doc. Meanwhile, Access is still open, and when the operator exits the Word doc, I want the Access code to close the word object.
I think I need to detetct the MS Word CLOSE event and run
oWord.Quit
Set oWord = Nothing
Can anybody bail me out on this one?
Thanks,
Brad
See enclosed code.
Private Sub cmdWord_Click()
Dim oWord As Word.Application
Dim oRange As Range
Const TemplatePath = "C:\WINDOWS\Profiles\Brad\My Documents\Access\Samples\Access_2000\NorthwindWordTemplate.dot"
Const SaveDocPath = "C:\WINDOWS\Profiles\Brad\My Documents\Access\Samples\Access_2000\"
Set oWord = CreateObject("Word.Application"
With oWord
.Documents.Add TemplatePath, NewTemplate:=False, DocumentType:=0
.Visible = True
.Activate
.WindowState = wdWindowStateMaximize
.WindowState = wdWindowStateNormal
End With
Set oRange = ActiveDocument.Range(Start:=0, End:=0)
oRange.ParagraphFormat.Alignment = wdAlignParagraphLeft
With oRange
.InsertParagraphAfter
.InsertAfter Me.CompanyName
.InsertParagraphAfter
.InsertAfter Me.ContactName
.Font.Name = "Arial"
.Font.Size = 12
.InsertParagraphAfter
End With
Exit Sub
EndItNow:
oWord.Quit
Set oWord = Nothing
End Sub
I have an MS Access form displaying a name and address (Northwind) having a button to open a new MS Word doc and head it up with a name and address displayed on the form.
Once the doc is opened with the header info inserted, I want the user to be able type whatever they want in the Word doc. Meanwhile, Access is still open, and when the operator exits the Word doc, I want the Access code to close the word object.
I think I need to detetct the MS Word CLOSE event and run
oWord.Quit
Set oWord = Nothing
Can anybody bail me out on this one?
Thanks,
Brad
See enclosed code.
Private Sub cmdWord_Click()
Dim oWord As Word.Application
Dim oRange As Range
Const TemplatePath = "C:\WINDOWS\Profiles\Brad\My Documents\Access\Samples\Access_2000\NorthwindWordTemplate.dot"
Const SaveDocPath = "C:\WINDOWS\Profiles\Brad\My Documents\Access\Samples\Access_2000\"
Set oWord = CreateObject("Word.Application"
With oWord
.Documents.Add TemplatePath, NewTemplate:=False, DocumentType:=0
.Visible = True
.Activate
.WindowState = wdWindowStateMaximize
.WindowState = wdWindowStateNormal
End With
Set oRange = ActiveDocument.Range(Start:=0, End:=0)
oRange.ParagraphFormat.Alignment = wdAlignParagraphLeft
With oRange
.InsertParagraphAfter
.InsertAfter Me.CompanyName
.InsertParagraphAfter
.InsertAfter Me.ContactName
.Font.Name = "Arial"
.Font.Size = 12
.InsertParagraphAfter
End With
Exit Sub
EndItNow:
oWord.Quit
Set oWord = Nothing
End Sub