D
David W. Fenton
I've got an app that began life in 1997 (A97) that I just converted
to A2K format last week and is running on Access 2002 and 2003 with
Word 2002 and Word 2003, respectively. On my computer (Office 2003)
I had to edit the merge templates to redefine the data source for
the merge, then save it, and everything works fine and dandy. But on
the one Office XP machine, it breaks. Here's the code:
Public Function wordMergeNow(strTemplate As String)
On Error GoTo errHandler
Dim objWord As Object
Dim docWord As Object
Set objWord = GetWordObject()
Set docWord = objWord.Documents.Add(strTemplate)
docWord.MailMerge.Execute ' IT ERRORS OUT HERE
docWord.Close False
objWord.Visible = True
objWord.Documents(1).Activate
objWord.Activate
objWord.WindowState = 1
wordMergeNow = True
exitRoutine:
Set docWord = Nothing
Set objWord = Nothing
DoCmd.Hourglass False
Exit Function
errHandler:
MsgBox err.Number & vbCrLf & " " & vbCrLf & err.Description, _
vbExclamation, "Error in mdlAccessToWord.wordMergeNow()"
Resume exitRoutine
End Function
If I go to the immediate window and make the Word application object
visible (with objWord.Visible = True), it's clear that the document
created from the template has no data source.
But if I do this interactively in Word 2002, there are no problems
-- the data source is defined and it merges without problem.
I've got macro security set to low, but that made no difference. I
do note that when I open it interactively, I get a notice that the
merge document is executing a SQL statement (yes, I know that, and
you don't need to tell me about it -- can't I turn that off?), so
maybe that's causing the problem? There has to be a way around this,
other than assigning the data source as part of the code above? This
code has been working for almost 10 years, and works just fine on
Office 2003 (with the edited template files).
Any ideas why it's breaking when run against Office 2002?
to A2K format last week and is running on Access 2002 and 2003 with
Word 2002 and Word 2003, respectively. On my computer (Office 2003)
I had to edit the merge templates to redefine the data source for
the merge, then save it, and everything works fine and dandy. But on
the one Office XP machine, it breaks. Here's the code:
Public Function wordMergeNow(strTemplate As String)
On Error GoTo errHandler
Dim objWord As Object
Dim docWord As Object
Set objWord = GetWordObject()
Set docWord = objWord.Documents.Add(strTemplate)
docWord.MailMerge.Execute ' IT ERRORS OUT HERE
docWord.Close False
objWord.Visible = True
objWord.Documents(1).Activate
objWord.Activate
objWord.WindowState = 1
wordMergeNow = True
exitRoutine:
Set docWord = Nothing
Set objWord = Nothing
DoCmd.Hourglass False
Exit Function
errHandler:
MsgBox err.Number & vbCrLf & " " & vbCrLf & err.Description, _
vbExclamation, "Error in mdlAccessToWord.wordMergeNow()"
Resume exitRoutine
End Function
If I go to the immediate window and make the Word application object
visible (with objWord.Visible = True), it's clear that the document
created from the template has no data source.
But if I do this interactively in Word 2002, there are no problems
-- the data source is defined and it merges without problem.
I've got macro security set to low, but that made no difference. I
do note that when I open it interactively, I get a notice that the
merge document is executing a SQL statement (yes, I know that, and
you don't need to tell me about it -- can't I turn that off?), so
maybe that's causing the problem? There has to be a way around this,
other than assigning the data source as part of the code above? This
code has been working for almost 10 years, and works just fine on
Office 2003 (with the edited template files).
Any ideas why it's breaking when run against Office 2002?