Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Mailmerge and Fax / November 2006

Tip: Looking for answers? Try searching our database.

Mail merge is not updating field names

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
shourie.varma@gmail.com - 13 Nov 2006 12:34 GMT
Hello,

I have written following code for mail merge.Even though it is not
giving any errors,It is not updating the "final.rtf".Can you suggest me
what is wrong here.

      Word.Application wrdApp;

       Word.Document oDataDoc;

       Word.MailMerge wrdMailMerge;

       Object oMissing = System.Type.Missing;

       Object oFalse = false;

       Object oTrue = true;

       Object oName = Server.MapPath("Mail.doc"); //source file

       Object oFileName = Server.MapPath("Final.rtf"); //distination
file

       Object oFileFormat = Word.WdSaveFormat.wdFormatRTF;

       wrdApp = new Word.ApplicationClass();

       wrdApp.Visible = true;

       wrdApp.WindowState = Word.WdWindowState.wdWindowStateMaximize;

       oDataDoc = wrdApp.Documents.Add(ref oName, ref oFalse, ref
oMissing, ref oMissing);

       oDataDoc.Activate();

      wrdMailMerge = oDataDoc.MailMerge;

       //wrdMailMerge.HighlightMergeFields = false;

       //wrdMailMerge.ViewMailMergeFieldCodes = 0; //this is for
showing the data instead of fieldnames

      Object oConnection = "DSN=Test"; //The DSN connection name

       Object oQuery = "SELECT FirstName FROM MailMerge"; // The query
to get data from the DSN

       //Object oSubType = Word.WdMergeSubType.wdMergeSubTypeWord;

        wrdMailMerge.OpenDataSource("", ref oFileFormat, ref oMissing,
ref oMissing, ref oTrue,
           ref oMissing, ref oMissing, ref oMissing, ref oFalse,
           ref oMissing, ref oMissing, ref oConnection, ref oQuery,
ref oMissing);

       wrdMailMerge.SuppressBlankLines = true;

       // Save document

       oDataDoc.SaveAs(ref oFileName, ref oFileFormat, ref oMissing,
ref oMissing, ref oTrue, ref oMissing, ref oMissing, ref oMissing, ref
oMissing, ref oMissing, ref oMissing);

       oDataDoc.Saved = true;

       wrdMailMerge = null;

       oDataDoc = null;

       wrdApp = null;

Regards,
Jagan Mohan Varma Pinnmaraju
shourie.varma@gmail.com - 13 Nov 2006 13:08 GMT
I am adding some more to previous question...

My document contains.....

Welcome to , <<FirstName>>

I should just replace <<FirstName>>
with data base content.

Regards,
jagan Mohan Varma Pinnamaraju.
Peter Jamieson - 13 Nov 2006 13:39 GMT
1. Can you tell whether or not Word is actually connecting to the data
source? My guess is that it probably is not. You probably need to take
account of  the following article, if you have not done so already:

http://support.microsoft.com/kb/825765/en-us

2.

<<
       //Object oSubType = Word.WdMergeSubType.wdMergeSubTypeWord;

        wrdMailMerge.OpenDataSource("", ref oFileFormat, ref oMissing,
ref oMissing, ref oTrue,
           ref oMissing, ref oMissing, ref oMissing, ref oFalse,
           ref oMissing, ref oMissing, ref oConnection, ref oQuery,
           ref oMissing);

You /may/ need to provide the Subtype parameter, as your commented out line
suggests, but
a. although this was necessary in Word 2002 and earlier versions of Word
2003, something seems to have changed in one of the fixes in the last year.
b. the value you need is probably called wdMergeSubTypeWord2000 and you
would need to pass it in your OpenDataSource call. (Actually I think
wdMergeSubTypeOther probably works now, too).

3. When you just supply a machine DSN in the Connection parameter, it must
contain all the information necessary to connect to the data source. if the
data source is SQL Server and you are not using Integrated Security, login
and/or password infromation is never saved in a machine DSN (you may have
supplied login and password when you set up the DSN, but in fact that is to
allow the ODBC driver to get additional information from the server, and the
login and/or password are not saved. You have to supply them as additional
items in the Connection parameter.

Peter Jamieson

> Hello,
>
[quoted text clipped - 70 lines]
> Regards,
> Jagan Mohan Varma Pinnmaraju
shourie.varma@gmail.com - 15 Nov 2006 05:45 GMT
Hi Peter,

Thanks Peter 2nd point helped me to solve this problem

Regards,
Jagan Mohan Varma Pinnamaraju.

> 1. Can you tell whether or not Word is actually connecting to the data
> source? My guess is that it probably is not. You probably need to take
[quoted text clipped - 106 lines]
> > Regards,
> > Jagan Mohan Varma Pinnmaraju
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.