473,395 Members | 1,466 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

word Mail merge

YY
For some reason my word mail merge throws execption when it reaches
wrdMailMerge = oDataDoc.MailMerge.

Can any body guide me in a clean wasy of doing mailerge from sql server 2005
table ? I really appreciate your help. Below is the code I tried hundred
times but throws exception.
try
{
Word.Application wrdApp;
Word.Document oDataDoc;
Word.MailMerge wrdMailMerge;
Object oMissing = System.Type.Missing;
Object oFalse = false;
Object oTrue = true;
Object oName = "c:\\templatefile.dot";
Object oFileName = "c"\\outputfile.doc";
Object oFileFormat = Word.WdSaveFormat.wdFormatRTF;
Object oConnection = "Data Source=sand01;Catalog=mydatabase;Integrated
Security=SSPI";;
Object oQuery = "select * from mytable" ;
Object oSubType = Word.WdMergeSubType.wdMergeSubTypeWord;
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;
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;
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;
}
catch (Exception exc)
{
}

Sep 24 '08 #1
0 1280

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Andy | last post by:
I am trying to do the following from an ASP.NET Web Application (C#). User fills out a form. The program takes those answers and merges them with a WORD document. I have tried the few examples...
2
by: Steve M | last post by:
I'm trying to do invoke the mail merge functionality of MS Word from a Python script. The situation is that I have a template Word document, and a record that I've generated in Python, and I want...
2
by: Aaron | last post by:
hello, i am perfoming a mail merge with the following code. Public Function MergeIt() Dim objWord As Object Set objWord = GetObject("C:\MyMerge.doc", "Word.Document") ' Make Word visible....
2
by: Colin Halliday | last post by:
I have a Word 2003 mail merge main document (form letter) that is linked to another Word document data source for the mail merge. If I open this doc using the Word GUI, it first asks me to...
8
by: Ron B | last post by:
Help!!! What am I doing wrong? I am working with Office 2003 and am trying to create a command button on an Access form that will create a mail merge in Word from an Access table. I want to...
3
by: Bishman | last post by:
Hi, I have some issues with the code below. These are: ONE: In code I open an existing document and 'attach' the Mail Merge data source, but the data is not poulating the merge fields...
6
by: crealesmith | last post by:
Firstly, I have no problem with mail merging to Word, VB code for that works perfectly. On one mail merge I need to merge 15 fields of data that are from 3 seperate records. The 3 records are all...
7
by: =?Utf-8?B?QmFkaXM=?= | last post by:
Hi, I'm trying to follow a mail merging example in C#.Net that I got from: http://support.microsoft.com/default.aspx/kb/301659 and in one the methods: Word.Application wrdApp; Word._Document...
1
by: Esther Lane | last post by:
Hello! First off, many many thanks to Albert who wrote the Mail Merge code for MS Access I am using. It has been working beautifully for a few years. However, my client just (without notice!)...
1
by: kayberrie | last post by:
I want to write a VBA mail merge code. I want to link the code/macro/dohicky to a nifty little button so it makes life easy. I think I can handle the button part, the code part - not so much. I know...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.