View Single Post
  #4   Report Post  
Posted to microsoft.public.dotnet.languages.vb,microsoft.public.word.mailmerge.fields
Chubbly Geezer
 
Posts: n/a
Default Mailmerge Automation Problems

I now have the code below. The name in the 'opendatasource' command now
points towards the *.odc file that was created when setting up the mail
merge doc.
When I try to execute, word shows a pop up stating that my merge field does
not exist. Would I like to remove it or use field 'M__' or 'M__1'.?
It appears to be looking at the wrong datasource. If I set the datasource
manually in my document, all works fine.

My code is below again.

thx


wrdApp = CreateObject("Word.Application")

wrdApp.Visible = True

wrdDoc =
wrdApp.Documents.Open("C:\temp\2005\WordDocument1\ WordDocument1\DeliveryAddress.doc")

wrdDoc.MailMerge.OpenDataSource(Name:="C:\Document s and Settings\pd.ISL\My
Documents\My Data Sources\webdev Subscriptions2
SubscriptionsPrintQueue.odc", ConfirmConversions:=False, ReadOnly:=True,
LinkToSource:=True, AddToRecentFiles:=False, PasswordDocument:="",
PasswordTemplate:="", WritePasswordDocument:="", WritePasswordTemplate:="",
Revert:=True, Format:=Word.WdOpenFormat.wdOpenFormatAuto, Connection:="data
source=WEBDEV; initial catalog=Subscriptions2; integrated security=SSPI;
persist security info=False; packet size=4096; Connect Timeout=300",
SQLStatement:="select * from subscriptionsprintqueue", SQLStatement1:="",
SubType:=Word.WdMergeSubType.wdMergeSubTypeOther)

wrdDoc.MailMerge.Destination =
Word.WdMailMergeDestination.wdSendToNewDocument

wrdDoc.MailMerge.Execute()





"Cindy M -WordMVP-" wrote in message
news:VA.0000bee5.00a5e089@speedy...
Hi Chubbly,

Hope you can help. I have created a mail merge word doc which seems to
work
fine. When I close and reload it asks if I wish to pull in the data.
Great.

However, I want to print the results of the mail merge from within a
VB.Net
app. I can create and load the word app/doc, but the document is not
opened
as a mail merge doc. In fact the mail merge fields just appear as text.

It would help if you'd show us the code you're using... You also need to
tell
us which version of Word you're testing on, which versions are targeted,
what
type of data source is involved and, if you know, which connection method
is
being used.

My best guess would be you're running into this:
"Opening This Will Run the Following SQL Command" Message When You Open a
Word
Document - 825765
http://support.microsoft.com?kbid=825765

In an automation environment, where this security measure is activated,
you
MUST use the OpenDataSource method to connect the data after the document
is
opened. The data source is unlinked without question when a mail merge
document
is opened by automation.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or
reply
in the newsgroup and not by e-mail :-)