OK, I think I suggested
doc.MailMerge.OpenDataSource _
Name:=Path & "IPdb.mdb", _
SQLStatement:="Select * From [Docs];"
but the ";" should not be there (even though it is normal SQL syntax).
/Normally/, the code I suggested should be enough.
But if that does not work, at the moment I can't see what is happening
here. Unfortunately I'm away next week so may not be able to pursue this
until after that, but here are a few suggestions...
Can you please open the document manually, then use VBA to output the values
of
ActiveDocument.MailMerge.DataSource.Name
ActiveDocument.MailMerge.DataSource.ConnectString
ActiveDocument.MailMerge.DataSource.QueryString
Are you also definitely not seeing the issues associated with the KB article
I mentioned earlier?
Does your database have either password security or user level (workgroup)
security set up?
Another thing to notice is the kind of dialog box that is displayed when
Word tries to open the file - if it has an Options button in the bottom
left, it's an ODBC dialog box, and that would typically mean that Word had
tried using OLEDB and failed, which probably means that the SQL syntax is
wrong.
FWIW,
'Connection:="TABLE [Docs]", _
This syntax in the Connection parameter is only used when you want to
connect using DDE, and is in fact optional as a SQL statement can be
provided in the SQLStatement parameter anyway.
'SubType:=wdMergeSubTypeWord2000
This parameter should only be used if you want to connect using DDE or
ODBC. It forces Word to use the old Word 2000 approach (and Word 2000 did
not support OLEDB).
Peter Jamieson
Don Petersen via OfficeKB.com said:
Sorry, I left some code out for brevity's sake. If it weren't there, then
I
would have gotten other run-time errors. Here is the full code:
Set app = CreateObject("Word.Application")
app.Visible = True
Set doc = app.Documents.Open(Path & "CatMergeUS.doc")
Set merge = app.ActiveDocument.MailMerge
doc.MailMerge.OpenDataSource _
Name:=Path & "IPdb.mdb", _
ConfirmConversions:=False, _
ReadOnly:=False, LinkToSource:=True, AddToRecentFiles:=False, _
SQLStatement:="Select * From 'Docs';" ' I've tried a number of
syntactic variations on this stmt based on a number of articles.
' These two lines are for another solution suggested by MS in a KBA.
'Connection:="TABLE [Docs]", _
'SubType:=wdMergeSubTypeWord2000
doc.MailMerge.MainDocumentType = wdDirectory
With merge
.Destination = wdSendToNewDocument
.MainDocumentType = wdDirectory
.Execute
The type of the document is still Letters. If I open the document
manually,
the type is Directory, as I desire.