Mail-merge with OLB 9.0 failing in 10.0

B

Bill

I have built a mail-merge automation process in Access
2000 on Windows 98 with these References (among others):

Microsoft Access 10.0 Object Library
Microsoft DAO 3.6 Object Library
Microsoft Word 8.0 Object Library

I've tested the process on Windows 2000 with the Word 9.0
OLB, and it works fine. However, my client also uses
Windows XP with the Word 10.0 Object Library, and the
automation fails. Is generic code available that will let
me run mail-merge automation in both 9.0 and 10.0? Here
are the relevant lines of existing code (line 3 is the
statement that fails now):

Dim objWord As Object
Set objWord = New Word.Application
objWord.Documents.Add <path and filename go here>
objWord.Visible = True
With objWord.ActiveDocument.Bookmarks
.Item("Field1").Range.Text = <data>
End With
Set objWord = Nothing

Thank you for your help!

-- Bill
 
S

SA

Bill:

You've got to move to what is called "late binding" rather than "early
binding" where you actually reference the object library in your app. With
late binding, you essentially allow the system to determine what version of
an application is available rather than being tied to one object library.
So you code would change to look like this:

Dim objWord As Object
Set objWord = CreateObject("Word.Application")
objWord.Documents.Add <path and filename go here>

And eliminate the reference to the Word object library.
 
D

Dev Ashish

Is generic code available that will let
me run mail-merge automation in both 9.0 and 10.0?

Remove the Early Binding and use Late Binding with CreateObject(see below).
You can then remove the Word reference all together.

Here
are the relevant lines of existing code (line 3 is the
statement that fails now):

Dim objWord As Object
'Set objWord = New Word.Application
set objWord = CreateObject("Word.Application")
objWord.Documents.Add <path and filename go here>
objWord.Visible = True
With objWord.ActiveDocument.Bookmarks
.Item("Field1").Range.Text = <data>
End With
Set objWord = Nothing

-- Dev
 
B

Bill

Steve --

This seems to work great! It tested well on my PC, and
the acid test is whether or not my client can get it to
work on her systems. I think this will solve the
problem. Thank you!

-- Bill
 
B

Bill

Dev --

This seems to work great! Your message confirmed the
approach recommended by Steve, so I'm reasonably certain
that this will work well on my client's PCs. I think Late
Binding will solve the problem. Thank you!

-- Bill
 

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