Word Merge Problem With Access 2002

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?
 
A

Arvin Meyer [MVP]

Hi David,

Just a WAG, cause the code looks fine. When you step through your code,
check the value of GetWordObject()
 
T

Tom van Stiphout

On 12 Dec 2008 04:00:33 GMT, "David W. Fenton"

I would always write:
Set objWord = GetWordObject()
if objWord is nothing then
Msgbox "Kindly first install Word ...."
else
'I want to see RIGHT AWAY what the object is doing
objWord.Visible = True

Not that I think that's the problem here.

I'm rusty on my Word object model. Can you inspect or set the data
source before you Execute? Something like:
debug.print docWord.MailMerge.DataSource
if docWord.MailMerge.DataSource = "" then
...

-Tom.
Microsoft Access MVP
 
F

Fred

I know 1/10 of what you guys do on that code, but two thoughts:

- Try a simple merge from Word with that same data source, and see if it
sees it. If not:

- I've sometimes seen queries "disappear" as a Word data source if there's
an "*" in the selecton criteria. (maybe Access vs. SQL, maybe machine
specific on whether or not such is an issue)
 
D

David W. Fenton

I would always write:
Set objWord = GetWordObject()
if objWord is nothing then
Msgbox "Kindly first install Word ...."

Well, this code is not running in the wild, but on a particular set
of PCs that always have Word installed (though many different
versions).
else
'I want to see RIGHT AWAY what the object is doing
objWord.Visible = True

Er, I don't *want* it visible, because the user should only see the
result of the merge.
Not that I think that's the problem here.

I'm rusty on my Word object model. Can you inspect or set the data
source before you Execute? Something like:
debug.print docWord.MailMerge.DataSource
if docWord.MailMerge.DataSource = "" then

I had to futz with this on another project once before, where for
some reason I had to assign the datasource every time I ran it. I
was hoping to avoid that, particularly given that it runs just fine
and dandy on Office 2003.
 
D

David W. Fenton

I know 1/10 of what you guys do on that code, but two thoughts:

- Try a simple merge from Word with that same data source, and see
if it sees it.

I alreayd said in my original post that if I use the template
manually, the data source is defined, and that it's only when done
programatically that it loses it.
If not:

- I've sometimes seen queries "disappear" as a Word data source if
there's an "*" in the selecton criteria. (maybe Access vs. SQL,
maybe machine specific on whether or not such is an issue)

It's running against a table, not a query.
 

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