Word Menus Not Operational After Mailmerge Initiated By Access

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
 
M

mfs_wgc

The Access version I was asking about was actually 2003 not 97.
Sorry !

I have now solved this by adding a line of code that minimizes the
Word window as follows :

With objWord
.WindowState = wdWindowStateMinimize 'This is necessary to
avoid the menus & Close button on the Word

'window from being disabled when it becomes visible
.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
.Activate
End With


I've no idea why this solves the problem but it does !

I'm posting this in case it helps someone else in the future.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top