M
mfs_wgc
I have a menu item on an Access (97) form that runs a mailmerge in
Word (2003). This works correctly but the toolbars and close button in
Word are dsiabled until the user performs one of the following
actions :
1. Minimises and then maximises the Word document window or
2. Uses the taskbar to go back to Access and then returns to Word
Does any one know how to prevent this behaviour ?
The relevant parts of the code on the Access menu item are :
(I've omitted quite a bit for clarity)
' Create a reference to an existing occurence of Word ...
' ... If it fails, Word is not open, so start it by creating a
reference to a new object
On Error Resume Next
Set objWord = GetObject(, "Word.Application")
If Err.Number <> 0 Then
Err.Clear
On Error GoTo Err_Handler
Set objWord = CreateObject("Word.Application")
Else
Err.Clear
On Error GoTo Err_Handler
End If
'Open a new document based on the selected template
strPathDocName = "D:\Templates\Employment Register Merge.dot"
Set objDocs = objWord.Documents
objDocs.Add strPathDocName
' Store the (temporary) name of the new document
strDocNameTemp = objWord.ActiveDocument
'Set the merge data source (for the doc opened above) to the text
file containing the names
' and then do the merge
With objWord
.ActiveDocument.MailMerge.OpenDataSource Name:=strTextFile,
Format:=wdOpenFormatText
.ActiveDocument.MailMerge.Destination = wdSendToNewDocument
.ActiveDocument.MailMerge.Execute
'Close the original document (not the merged doc)
.Documents(strDocNameTemp).Close
SaveChanges:=wdDoNotSaveChanges
.Visible = True
'Bring Word window to the front
.Activate
End With
rsForm.Close
rsTemp.Close
Set rsForm = Nothing
Set rsTemp = Nothing
Word (2003). This works correctly but the toolbars and close button in
Word are dsiabled until the user performs one of the following
actions :
1. Minimises and then maximises the Word document window or
2. Uses the taskbar to go back to Access and then returns to Word
Does any one know how to prevent this behaviour ?
The relevant parts of the code on the Access menu item are :
(I've omitted quite a bit for clarity)
' Create a reference to an existing occurence of Word ...
' ... If it fails, Word is not open, so start it by creating a
reference to a new object
On Error Resume Next
Set objWord = GetObject(, "Word.Application")
If Err.Number <> 0 Then
Err.Clear
On Error GoTo Err_Handler
Set objWord = CreateObject("Word.Application")
Else
Err.Clear
On Error GoTo Err_Handler
End If
'Open a new document based on the selected template
strPathDocName = "D:\Templates\Employment Register Merge.dot"
Set objDocs = objWord.Documents
objDocs.Add strPathDocName
' Store the (temporary) name of the new document
strDocNameTemp = objWord.ActiveDocument
'Set the merge data source (for the doc opened above) to the text
file containing the names
' and then do the merge
With objWord
.ActiveDocument.MailMerge.OpenDataSource Name:=strTextFile,
Format:=wdOpenFormatText
.ActiveDocument.MailMerge.Destination = wdSendToNewDocument
.ActiveDocument.MailMerge.Execute
'Close the original document (not the merged doc)
.Documents(strDocNameTemp).Close
SaveChanges:=wdDoNotSaveChanges
.Visible = True
'Bring Word window to the front
.Activate
End With
rsForm.Close
rsTemp.Close
Set rsForm = Nothing
Set rsTemp = Nothing