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 / August 2007

Tip: Looking for answers? Try searching our database.

Mailmerge hangs at OpenDataSource

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
John G - 24 Aug 2007 07:31 GMT
I have the follow app that always hangs when i get to the
OpenDataSource method.  Any Ideas?  Thanks in Advance

Word.Application wrdApp;
           Word.Document oDataDoc;
           Word.MailMerge wrdMailMerge;
           Object oMissing = System.Type.Missing;
           Object oFalse = false;
           Object oTrue = true;
           Object oName = "C:\\Documents and Settings\\John\\Desktop\
\EDP\\cardprocess\\idcardsmmeastern-x4.doc";
           Object oFileName =  @"c:\saved.rtf";
           Object oFileFormat = Word.WdSaveFormat.wdFormatRTF;
           // Starting the Word Application

           wrdApp = new Word.ApplicationClass();
           wrdApp.Visible = true;
           wrdApp.WindowState =
Word.WdWindowState.wdWindowStateMaximize;

           // Open the template
           oDataDoc = wrdApp.Documents.Add(ref oName, ref oFalse, ref
oMissing, ref oMissing);
           oDataDoc.Activate();

           // Document 2 mailmerge format
           wrdMailMerge = oDataDoc.MailMerge;
           wrdMailMerge.HighlightMergeFields = false;
           //wrdMailMerge.ViewMailMergeFieldCodes = 0; //this is for
showing the data instead of fieldnames
           // The data part

           Object oConnection = "DSN=Edentalnew";  //The DSN
connection name
           Object oQuery = "SELECT top 10 mblname LastName, mbfname
FirstName FROM [lumemb]"; // The query to get data from the DSN
           Object oSubType = Word.WdMergeSubType.wdMergeSubTypeWord;

           //Open the data source and merge the fields
           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, ref oMissing, ref oSubType);
           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, ref oMissing, ref
oMissing, ref oMissing, ref oMissing, ref oMissing);
           oDataDoc.Saved = true;

           // Unload objects from the memory
           wrdMailMerge = null;
           oDataDoc = null;
           wrdApp = null;
Peter Jamieson - 27 Aug 2007 10:56 GMT
First, I would try

Object oSubType = Word.WdMergeSubType.wdMergeSubTypeWord2000;

Next, I would probably try to use a much simpler piece of SQL (SELECT * FROm
[mytable] until everything else is sorted out.

Next, I would check that the DSN contained everything needed for connection
(typically, username and password are not saved in the DSN even though it
sometimes appears from the DSN setup that they are. With SQL Server, you
should however be OK if you are using Windows Integrated Security.

Next, I would probably add an alias name for the /table/ and use it to
qualify each field name.
Signature

Peter Jamieson
http://tips.pjmsn.me.uk

>I have the follow app that always hangs when i get to the
> OpenDataSource method.  Any Ideas?  Thanks in Advance
[quoted text clipped - 52 lines]
>            oDataDoc = null;
>            wrdApp = null;
John G - 28 Aug 2007 19:55 GMT
Thanks Peter.  I tried countless examples.  I took the same example
and did it on another machine and it worked fine. Not sure what it
could be.:(  Thanks for your help

On Aug 27, 5:56 am, "Peter Jamieson" <p...@KillmapSpjjnet.demon.co.uk>
wrote:
> First, I would try
>
[quoted text clipped - 71 lines]
>
> - Show quoted text -
Peter Jamieson - 29 Aug 2007 07:45 GMT
Does the same DSN work correctly with other software (e.g. Excel, MS Query)
on the original machine?

Signature

Peter Jamieson
http://tips.pjmsn.me.uk

> Thanks Peter.  I tried countless examples.  I took the same example
> and did it on another machine and it worked fine. Not sure what it
[quoted text clipped - 79 lines]
>>
>> - Show quoted text -

Rate this thread:






 
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.