Macro Problems (cross version) and Mail Merges

A

Anthony Wieser

I have a macro that seems simple enough:
Sub AutoNew()
'
Set ad = ActiveDocument
'Set the path below to where you've stored your contacts
sDBPath = "\\server\folder\database.mdb"


With ActiveDocument.MailMerge
.OpenDataSource Name:=sDBPath, _
SQLStatement:="SELECT * FROM [MailMerge] WHERE Selected=-1 AND
Blacklist<>-1 and NeverMail <> -1 ORDER BY Name"
.Destination = wdSendToNewDocument
.Execute
End With
ad.Close SaveChanges:=wdDoNotSaveChanges
End Sub

So, it's simple enough, run a mailmerge on a file using an access database
when you open the template file this is stored in.

CASE 1: Office XP on Vista, Access not installed

This used to work, on every machine I tried it on (obviously not enough),
but now running on Office XP on Vista, I get message box pop up that says:

Title: "Open Database Connectivity Error"
Contents of dialog: "Data source name not found and no default driver
specified".

The file exists on the disk, although access is not installed on this
machine.

After the error is dismissed, I get another error message box:
which contains this text:

ODBC error: [Microsoft][ODBC Driver Manager]Data source name not found and
no default driver specified.
Sql State: IM002
Return Code: SQL_ERROR

If I dismiss this error, the mail merge correctly gets the new data, but the
blank document isn't closed.

CASE 2: Office 2007 SP1 on Vista, Access 2007 Installed

No error message, but when the macro tries to run, I get a warning to begin
with, which says:
"The macros in theis project are disabled. Please refer to the online help
or documentation of the host application to determine how to enable macros."

Ok, fair enough, that's the default for office 2007

So I click ok, and then see the security warning that says "Macros have been
disabled", and click the options button.
Then I click Enable this content, and choose OK.
The macro starts to run, and then after its done the mailmerge into a new
document, I get this error:

Title: Microsoft Visual Basic
Contents:
Run-time error '-2147417848 (80010108)':
Automation Error
The object invoked has disconnected from its clients.

When I click End, Word 2007 crashes.

Now, if instead, I run it with macros enabled (not recommended), it all
works fine as expected.

CASE 3: Office 2000 on Windows XP SP2
Everything runs just fine.

So there you have it. I can't work out what I'm doing wrong, or how I'm
supposed to get this to work on all of the platforms.
Does anyone see anything stupid I've done?

Anthony Wieser
Wieser Software Ltd
 

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