View Single Post
  #10   Report Post  
Peter Jamieson
 
Posts: n/a
Default

BTW, I meant to say before that the code you posted is mixing objects a bit
(once you've set up the doc object variable it's probably better to use it
rather than refer to ActiveDocument again). It may not make any difference
in practice but...

Set app = CreateObject("Word.Application")
app.Visible = True
Set doc = app.Documents.Open(Path & "CatMergeUS.doc")


IMO at this point it might be better to use either something like

With doc.MailMerge
.OpenDataSource _
Name:=Path & "IPdb.mdb", _
SQLStatement:="Select * From [Docs]"
.MainDocumentType = wdDirectory
.Destination = wdSendToNewDocument
.MainDocumentType = wdDirectory
.Execute
End With

or

Set merge = doc.MailMerge
with merge
.OpenDataSource _
Name:=Path & "IPdb.mdb", _
SQLStatement:="Select * From [Docs]"
.MainDocumentType = wdDirectory
.Destination = wdSendToNewDocument
.MainDocumentType = wdDirectory
.Execute
end with


"Don Petersen via OfficeKB.com" wrote in message
...
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.

--
Message posted via http://www.officekb.com