Automate mail merge (1 Viewer)

RussG

Registered User.
Local time
Today, 21:00
Joined
Feb 10, 2001
Messages
178
I have created a module to automate a mail merge form access. I used the following code from the MS support site:

Function MergeIt()
Dim objWord As Word.Document
Set objWord = GetObject("C:\MyMerge.doc", "Word.Document")
' Make Word Visible.
objWord.Application.Visible = True
' Set the Mail Merge data Source.
objWord.MailMerge.OpenDataSource Name:="c:\CHC.MDB", LinkToSource:=True, Connection:="TABLE tblCustomers", SQLStatement:="Select * from [tblCustomers]"
' Execute the Mail Merge.
objWord.MailMerge.Execute
End Function

I have triple checked the code and it is same as MS code.

I am getting an error message saying C:\CHC.MDB doesn't exist, but it does!
I have tried renaming it, some friends have had a look and can't see anything wrong other than the MS dos name is different than CHC.MDB (it is CHCMDB~1.MDB) I don't know if this makes any difference.

Any help gratefully received.

Russ
 

John.Woody

Registered User.
Local time
Today, 21:00
Joined
Sep 10, 2001
Messages
354
It appears as though CHC.mdb is not the full name of the database. It may well be longer than 8 characters which is why DOS has put the ~ sign in. Find out what the full name of CHC.mdb is and put that in your code.

HTH
John
 

RussG

Registered User.
Local time
Today, 21:00
Joined
Feb 10, 2001
Messages
178
Thans John, that was it, I had to reference the file by using the DOS name.

As a matter of interest when it ran it opened 2 instances of Access ( common problem), however I cured this by removing the last line of code and it seemed to work fine.

I will have to play with this some more.

Thanks again.

Russ
 

Users who are viewing this thread

Top Bottom