473,654 Members | 3,062 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Creating a mail merge document using C#.

Hey, all. I'm trying to develop a C# app that creates Word 2003 mail merge
documents with an Oracle 9i database as the datasource. I used the following
as an example of how I can start out:

http://support.microsoft.com/default...b;EN-US;301659

The problem is that the code provided doesn't allow me to add more users to
the mail merge data file. When I try to add an additional user with the
following code, I get this error when I try to build:

"No overload for method 'FillRow' takes '6' arguments"

Here's the code I want to work. Please help.

<code>
private void FillRow(Word._D ocument oDoc, int Row, string Text1,
string Text2, string Text3, string Text4, string Text5)
{
// Insert the data into the specific cell.
oDoc.Tables[1].Cell(Row,1).Ra nge.InsertAfter (Text1);
oDoc.Tables[1].Cell(Row,2).Ra nge.InsertAfter (Text2);
oDoc.Tables[1].Cell(Row,3).Ra nge.InsertAfter (Text3);
oDoc.Tables[1].Cell(Row,4).Ra nge.InsertAfter (Text4);
oDoc.Tables[1].Cell(Row,5).Ra nge.InsertAfter (Text5);
}

private void CreateMailMerge DataFile()
{
Word._Document oDataDoc;
int iCount;

Object oName = "C:\\DataDoc.do c";
Object oHeader = "FirstName, LastName, Address, CityStateZip";
wrdDoc.MailMerg e.CreateDataSou rce(ref oName,ref oMissing,
ref oMissing,ref oHeader, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing);

// Open the file to insert data.
oDataDoc = wrdApp.Document s.Open(ref oName,ref oMissing,
ref oMissing, ref oMissing,ref oMissing,ref oMissing,
ref oMissing,ref oMissing,ref oMissing,ref oMissing,
ref oMissing,ref oMissing,ref oMissing,ref oMissing,
ref oMissing, ref oMissing);

for (iCount=1; iCount<=2; iCount++)
{
oDataDoc.Tables[1].Rows.Add(ref oMissing);
}
// Fill in the data.
FillRow(oDataDo c, 2, "Steve", "DeBroux",
"4567 Main Street", "Buffalo, NY 98052");
FillRow(oDataDo c, 3, "Jan", "Miksovsky" ,
"1234 5th Street", "Charlotte, NC 98765");
FillRow(oDataDo c, 4, "Brian", "Valentine" ,
"12348 78th Street Apt. 214",
"Lubbock, TX 25874");
FillRow(oDataDo c, 5, "FifthFirst ", "FifthLast" ,
"6666 Phoney Street",
"Cowtown, CA 90218");
// Save and close the file.
oDataDoc.Save() ;
oDataDoc.Close( ref oFalse, ref oMissing, ref oMissing);
}
</code>
Jul 21 '05 #1
6 12651
It's telling you that there the FillRow method that you are calling does not
match the signature.

Your signature for the method is:
private void FillRow(Word._D ocument oDoc, int Row, string Text1,
string Text2, string Text3, string Text4, string Text5)
Note that there are 7 arguments here.

However, when you are calling it here:
FillRow(oDataDo c, 4, "Brian", "Valentine" ,
"12348 78th Street Apt. 214",
"Lubbock, TX 25874");
You have only provided 6 parameters.

--
Ben Lucas
Lead Developer
Solien Technology, Inc.
www.solien.com
"campwes" <ca*****@discus sions.microsoft .com> wrote in message
news:85******** *************** ***********@mic rosoft.com... Hey, all. I'm trying to develop a C# app that creates Word 2003 mail
merge
documents with an Oracle 9i database as the datasource. I used the
following
as an example of how I can start out:

http://support.microsoft.com/default...b;EN-US;301659

The problem is that the code provided doesn't allow me to add more users
to
the mail merge data file. When I try to add an additional user with the
following code, I get this error when I try to build:

"No overload for method 'FillRow' takes '6' arguments"

Here's the code I want to work. Please help.

<code>
private void FillRow(Word._D ocument oDoc, int Row, string Text1,
string Text2, string Text3, string Text4, string Text5)
{
// Insert the data into the specific cell.
oDoc.Tables[1].Cell(Row,1).Ra nge.InsertAfter (Text1);
oDoc.Tables[1].Cell(Row,2).Ra nge.InsertAfter (Text2);
oDoc.Tables[1].Cell(Row,3).Ra nge.InsertAfter (Text3);
oDoc.Tables[1].Cell(Row,4).Ra nge.InsertAfter (Text4);
oDoc.Tables[1].Cell(Row,5).Ra nge.InsertAfter (Text5);
}

private void CreateMailMerge DataFile()
{
Word._Document oDataDoc;
int iCount;

Object oName = "C:\\DataDoc.do c";
Object oHeader = "FirstName, LastName, Address, CityStateZip";
wrdDoc.MailMerg e.CreateDataSou rce(ref oName,ref oMissing,
ref oMissing,ref oHeader, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing);

// Open the file to insert data.
oDataDoc = wrdApp.Document s.Open(ref oName,ref oMissing,
ref oMissing, ref oMissing,ref oMissing,ref oMissing,
ref oMissing,ref oMissing,ref oMissing,ref oMissing,
ref oMissing,ref oMissing,ref oMissing,ref oMissing,
ref oMissing, ref oMissing);

for (iCount=1; iCount<=2; iCount++)
{
oDataDoc.Tables[1].Rows.Add(ref oMissing);
}
// Fill in the data.
FillRow(oDataDo c, 2, "Steve", "DeBroux",
"4567 Main Street", "Buffalo, NY 98052");
FillRow(oDataDo c, 3, "Jan", "Miksovsky" ,
"1234 5th Street", "Charlotte, NC 98765");
FillRow(oDataDo c, 4, "Brian", "Valentine" ,
"12348 78th Street Apt. 214",
"Lubbock, TX 25874");
FillRow(oDataDo c, 5, "FifthFirst ", "FifthLast" ,
"6666 Phoney Street",
"Cowtown, CA 90218");
// Save and close the file.
oDataDoc.Save() ;
oDataDoc.Close( ref oFalse, ref oMissing, ref oMissing);
}
</code>

Jul 21 '05 #2
Ben,

That makes sense - thanks! What I don't understand now is that when I leave
the as:

private void FillRow(Word._D ocument oDoc, int Row, string Text1,
string Text2, string Text3, string Text4)
{
// Insert the data into the specific cell.
oDoc.Tables[1].Cell(Row,1).Ra nge.InsertAfter (Text1);
oDoc.Tables[1].Cell(Row,2).Ra nge.InsertAfter (Text2);
oDoc.Tables[1].Cell(Row,3).Ra nge.InsertAfter (Text3);
oDoc.Tables[1].Cell(Row,4).Ra nge.InsertAfter (Text4);
}

and add a new name to the bottom of the name/address list, the last two
names get smushed together like so:

BrianFifthFirst ValentineFifthL ast
12348 78th Street Apt. 2146666 Phoney Street
Lubbock, TX 25874Cowtown, CA 90218

I just need to add additional rows to the merge data file. Thanks again.
Jul 21 '05 #3
Are you perhaps using the same Row number for the 4th and 5th rows?

--
Ben Lucas
Lead Developer
Solien Technology, Inc.
www.solien.com

"campwes" <ca*****@discus sions.microsoft .com> wrote in message
news:5D******** *************** ***********@mic rosoft.com...
Ben,

That makes sense - thanks! What I don't understand now is that when I
leave
the as:

private void FillRow(Word._D ocument oDoc, int Row, string Text1,
string Text2, string Text3, string Text4)
{
// Insert the data into the specific cell.
oDoc.Tables[1].Cell(Row,1).Ra nge.InsertAfter (Text1);
oDoc.Tables[1].Cell(Row,2).Ra nge.InsertAfter (Text2);
oDoc.Tables[1].Cell(Row,3).Ra nge.InsertAfter (Text3);
oDoc.Tables[1].Cell(Row,4).Ra nge.InsertAfter (Text4);
}

and add a new name to the bottom of the name/address list, the last two
names get smushed together like so:

BrianFifthFirst ValentineFifthL ast
12348 78th Street Apt. 2146666 Phoney Street
Lubbock, TX 25874Cowtown, CA 90218

I just need to add additional rows to the merge data file. Thanks again.

Jul 21 '05 #4


"Ben Lucas" wrote:
No, because when I add a fifth line:

oDoc.Tables[1].Cell(Row,4).Ra nge.InsertAfter (Text4);

I get an error. It's almost as if this code won't take more than 4
names/addresses. Any other ideas?

Thanks.

-campwes
Are you perhaps using the same Row number for the 4th and 5th rows?

--
Ben Lucas
Lead Developer
Solien Technology, Inc.
www.solien.com


Jul 21 '05 #5
All,

I figured it out - stupid newbie mistake. That's what I get for trying to
learn C# for a new project.

I needed to increment the Boolean value in the "for" clause:

for (iCount=1; iCount<=2; iCount++)

to:

for (iCount=1; iCount<=4; iCount++).

Doing this allows me to add as many contacts to the list as I want.

"campwes" wrote:


"Ben Lucas" wrote:
No, because when I add a fifth line:

oDoc.Tables[1].Cell(Row,4).Ra nge.InsertAfter (Text4);

I get an error. It's almost as if this code won't take more than 4
names/addresses. Any other ideas?

Thanks.

-campwes
Are you perhaps using the same Row number for the 4th and 5th rows?

--
Ben Lucas
Lead Developer
Solien Technology, Inc.
www.solien.com

Jul 21 '05 #6
I forget where I saw that FillRow method before, but I know I downloaded it
from someplace. I was using it but found some limitations and it was slow.
In my search for the solution to the problem I was having, I found this
method and it works much better. (Sorry it's in VB .NET) I tried to strip
anything out that was custom to my application.

Private Function CreateDataSourc e(ByVal voWordApp As Word.Applicatio n)
Dim oWrdDataDoc As Word.DocumentCl ass
Dim i As Integer
Dim oDS As DataSet

oDS = 'Open your Dataset here
Dim sColumns As String
Dim sFldName As String
Dim sValues As String
Dim oDR As DataRow

For i = 0 To nColCnt - 1
'Create a tab delimited string of your column names
sColumns &= oDS.Tables(0).C olumns(i).Colum nName & vbTab
Next i

'strip off the last tab
sColumns = sColumns .Substring(0, sColumns.LastIn dexOf(vbTab)) &
vbcrlf

'Create our data document
oWrdDataDoc = voWordApp.Docum ents.Add()
'Create a table with a header row.
Dim oWrdRange As Word.Range = oWrdDataDoc.Con tent
With oWrdRange
.Collapse(WdCol lapseDirection. wdCollapseEnd)
.InsertAfter(Te xt:=sColumns)
.Collapse(WdCol lapseDirection. wdCollapseEnd)

'Now load our data into our table
For Each oDR In oDS.Tables(0).R ows
sValues = ""

'Get the values for our table
For Each sFldName In sColumns.Split( vbTab)
'Read each VALUE out of the datatable
sValues &= Trim(oDR.Item(s FldName)) & vbTab
Next sFldName

'Strip the last vbTab character
sValues = sValues.Substri ng(0, sValues.LastInd exOf(vbTab))

.InsertAfter(Te xt:=sValues & vbCrLf) 'Insert the new row of
data
.Collapse(WdCol lapseDirection. wdCollapseEnd)
Next oDR

.Start = oWrdDataDoc.Ran ge.Start

'Here is where the table is created
.ConvertToTable (vbTab)

Dim oWrdSelection As Word.Selection = voWordApp.Selec tion
oWrdSelection.T ables.Item(1).A llowAutoFit = False
oWrdSelection = Nothing
End With

oWrdDataDoc.Sav eAs("c:\temp\da tadoc.doc")

oWrdDataDoc.Clo se(False)
End Function
#End Region
"campwes" wrote:
Hey, all. I'm trying to develop a C# app that creates Word 2003 mail merge
documents with an Oracle 9i database as the datasource. I used the following
as an example of how I can start out:

http://support.microsoft.com/default...b;EN-US;301659

The problem is that the code provided doesn't allow me to add more users to
the mail merge data file. When I try to add an additional user with the
following code, I get this error when I try to build:

"No overload for method 'FillRow' takes '6' arguments"

Here's the code I want to work. Please help.

<code>
private void FillRow(Word._D ocument oDoc, int Row, string Text1,
string Text2, string Text3, string Text4, string Text5)
{
// Insert the data into the specific cell.
oDoc.Tables[1].Cell(Row,1).Ra nge.InsertAfter (Text1);
oDoc.Tables[1].Cell(Row,2).Ra nge.InsertAfter (Text2);
oDoc.Tables[1].Cell(Row,3).Ra nge.InsertAfter (Text3);
oDoc.Tables[1].Cell(Row,4).Ra nge.InsertAfter (Text4);
oDoc.Tables[1].Cell(Row,5).Ra nge.InsertAfter (Text5);
}

private void CreateMailMerge DataFile()
{
Word._Document oDataDoc;
int iCount;

Object oName = "C:\\DataDoc.do c";
Object oHeader = "FirstName, LastName, Address, CityStateZip";
wrdDoc.MailMerg e.CreateDataSou rce(ref oName,ref oMissing,
ref oMissing,ref oHeader, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing);

// Open the file to insert data.
oDataDoc = wrdApp.Document s.Open(ref oName,ref oMissing,
ref oMissing, ref oMissing,ref oMissing,ref oMissing,
ref oMissing,ref oMissing,ref oMissing,ref oMissing,
ref oMissing,ref oMissing,ref oMissing,ref oMissing,
ref oMissing, ref oMissing);

for (iCount=1; iCount<=2; iCount++)
{
oDataDoc.Tables[1].Rows.Add(ref oMissing);
}
// Fill in the data.
FillRow(oDataDo c, 2, "Steve", "DeBroux",
"4567 Main Street", "Buffalo, NY 98052");
FillRow(oDataDo c, 3, "Jan", "Miksovsky" ,
"1234 5th Street", "Charlotte, NC 98765");
FillRow(oDataDo c, 4, "Brian", "Valentine" ,
"12348 78th Street Apt. 214",
"Lubbock, TX 25874");
FillRow(oDataDo c, 5, "FifthFirst ", "FifthLast" ,
"6666 Phoney Street",
"Cowtown, CA 90218");
// Save and close the file.
oDataDoc.Save() ;
oDataDoc.Close( ref oFalse, ref oMissing, ref oMissing);
}
</code>

Jul 21 '05 #7

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

Similar topics

2
12511
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 to output a new Word .doc file with the template filled in with the record I've generated. (To refresh your memory, in Word a mailmerge is achieved by a) under Tools -> Letters and Mailings, check off Show Mail Merge Toolbar; b) open a document...
8
9511
by: Squirrel | last post by:
Hi everyone, I've created a mail merge Word doc. (using Office XP) , the data source is an Access query. Functionality I'm attempting to set up is: User sets a boolean field to true for each person for whom a mail merge letter is desired. The query reads address info from the table for each record where is true.
9
4319
by: Neil Ginsberg | last post by:
I have a strange situation using Access to automate a Word mail merge. Using Access 2000 and Word 2000, the code opens Word, opens the document in Word, sets a table in the calling Access application as the data source, and then performs a merge. Everything works fine. However, when a user uses it in Access 2002 and Word 2002, an extra instance of the Access application is opened and remains open at the end. Sometimes it remains open
6
1550
by: campwes | last post by:
Hey, all. I'm trying to develop a C# app that creates Word 2003 mail merge documents with an Oracle 9i database as the datasource. I used the following as an example of how I can start out: http://support.microsoft.com/default.aspx?scid=kb;EN-US;301659 The problem is that the code provided doesn't allow me to add more users to the mail merge data file. When I try to add an additional user with the following code, I get this error...
4
5445
by: lesperancer | last post by:
I have 3 tables (office97) tblQuote quoteNbr tblDetails ( quote : 1 <-> M: quoteDetails) quoteNbr detailLine product value
5
1936
by: darnnews | last post by:
Hi, I have been creating a database to keep track of press clippings, but I have hit a couple stumbling blocks. Any help is much appreciate. 1) Seeing if my query is done I have the following code to define a query. I run the query and then get a record deleted errors (3167) when I go to export to a spreadsheet. It works if I put in a delay between the query and the
1
4947
by: mr k | last post by:
Hi, I wanted to use mail merge with forms but Text form fields are not retained during mail merge in Word, I got the code from Microsoft but it doesn't remember the text form field options such as the maximum length of the text (which I need) and the text format (would be ideal but can do without if need be) I have posted the code below, so please can you help!?? Thanks in advance... Sub PreserveMailMergeFormFieldsNewDoc() Dim...
0
1208
by: dhvenkat | last post by:
Hi all, Im facing issues in generating the second mail-merge document when the first document created is still open. Its a web based application, and we submit the details for mail-merge after which document gets created. Im using VBA code to do mail-merge functionality. When I run the application the first time word document gets created (for 1 row and n rows - based on the number of records returned from database, so many pages /...
1
6543
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!) upgraded from Access 2000 to Access 2007. Now that component is failing. The merge is building the data source file fine (text file named merge.888). I am providing an absolute path reference to the word file being used for the mail merge. ...
0
8376
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8290
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8815
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8594
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6161
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5622
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4294
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2716
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1596
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.