473,394 Members | 1,752 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,394 software developers and data experts.

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._Document 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).Range.InsertAfter(Text1);
oDoc.Tables[1].Cell(Row,2).Range.InsertAfter(Text2);
oDoc.Tables[1].Cell(Row,3).Range.InsertAfter(Text3);
oDoc.Tables[1].Cell(Row,4).Range.InsertAfter(Text4);
oDoc.Tables[1].Cell(Row,5).Range.InsertAfter(Text5);
}

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

Object oName = "C:\\DataDoc.doc";
Object oHeader = "FirstName, LastName, Address, CityStateZip";
wrdDoc.MailMerge.CreateDataSource(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.Documents.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(oDataDoc, 2, "Steve", "DeBroux",
"4567 Main Street", "Buffalo, NY 98052");
FillRow(oDataDoc, 3, "Jan", "Miksovsky",
"1234 5th Street", "Charlotte, NC 98765");
FillRow(oDataDoc, 4, "Brian", "Valentine",
"12348 78th Street Apt. 214",
"Lubbock, TX 25874");
FillRow(oDataDoc, 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 12624
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._Document 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(oDataDoc, 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*****@discussions.microsoft.com> wrote in message
news:85**********************************@microsof t.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._Document 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).Range.InsertAfter(Text1);
oDoc.Tables[1].Cell(Row,2).Range.InsertAfter(Text2);
oDoc.Tables[1].Cell(Row,3).Range.InsertAfter(Text3);
oDoc.Tables[1].Cell(Row,4).Range.InsertAfter(Text4);
oDoc.Tables[1].Cell(Row,5).Range.InsertAfter(Text5);
}

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

Object oName = "C:\\DataDoc.doc";
Object oHeader = "FirstName, LastName, Address, CityStateZip";
wrdDoc.MailMerge.CreateDataSource(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.Documents.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(oDataDoc, 2, "Steve", "DeBroux",
"4567 Main Street", "Buffalo, NY 98052");
FillRow(oDataDoc, 3, "Jan", "Miksovsky",
"1234 5th Street", "Charlotte, NC 98765");
FillRow(oDataDoc, 4, "Brian", "Valentine",
"12348 78th Street Apt. 214",
"Lubbock, TX 25874");
FillRow(oDataDoc, 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._Document oDoc, int Row, string Text1,
string Text2, string Text3, string Text4)
{
// Insert the data into the specific cell.
oDoc.Tables[1].Cell(Row,1).Range.InsertAfter(Text1);
oDoc.Tables[1].Cell(Row,2).Range.InsertAfter(Text2);
oDoc.Tables[1].Cell(Row,3).Range.InsertAfter(Text3);
oDoc.Tables[1].Cell(Row,4).Range.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 ValentineFifthLast
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*****@discussions.microsoft.com> wrote in message
news:5D**********************************@microsof t.com...
Ben,

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

private void FillRow(Word._Document oDoc, int Row, string Text1,
string Text2, string Text3, string Text4)
{
// Insert the data into the specific cell.
oDoc.Tables[1].Cell(Row,1).Range.InsertAfter(Text1);
oDoc.Tables[1].Cell(Row,2).Range.InsertAfter(Text2);
oDoc.Tables[1].Cell(Row,3).Range.InsertAfter(Text3);
oDoc.Tables[1].Cell(Row,4).Range.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 ValentineFifthLast
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).Range.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).Range.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 CreateDataSource(ByVal voWordApp As Word.Application)
Dim oWrdDataDoc As Word.DocumentClass
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).Columns(i).ColumnName & vbTab
Next i

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

'Create our data document
oWrdDataDoc = voWordApp.Documents.Add()
'Create a table with a header row.
Dim oWrdRange As Word.Range = oWrdDataDoc.Content
With oWrdRange
.Collapse(WdCollapseDirection.wdCollapseEnd)
.InsertAfter(Text:=sColumns)
.Collapse(WdCollapseDirection.wdCollapseEnd)

'Now load our data into our table
For Each oDR In oDS.Tables(0).Rows
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(sFldName)) & vbTab
Next sFldName

'Strip the last vbTab character
sValues = sValues.Substring(0, sValues.LastIndexOf(vbTab))

.InsertAfter(Text:=sValues & vbCrLf) 'Insert the new row of
data
.Collapse(WdCollapseDirection.wdCollapseEnd)
Next oDR

.Start = oWrdDataDoc.Range.Start

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

Dim oWrdSelection As Word.Selection = voWordApp.Selection
oWrdSelection.Tables.Item(1).AllowAutoFit = False
oWrdSelection = Nothing
End With

oWrdDataDoc.SaveAs("c:\temp\datadoc.doc")

oWrdDataDoc.Close(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._Document 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).Range.InsertAfter(Text1);
oDoc.Tables[1].Cell(Row,2).Range.InsertAfter(Text2);
oDoc.Tables[1].Cell(Row,3).Range.InsertAfter(Text3);
oDoc.Tables[1].Cell(Row,4).Range.InsertAfter(Text4);
oDoc.Tables[1].Cell(Row,5).Range.InsertAfter(Text5);
}

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

Object oName = "C:\\DataDoc.doc";
Object oHeader = "FirstName, LastName, Address, CityStateZip";
wrdDoc.MailMerge.CreateDataSource(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.Documents.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(oDataDoc, 2, "Steve", "DeBroux",
"4567 Main Street", "Buffalo, NY 98052");
FillRow(oDataDoc, 3, "Jan", "Miksovsky",
"1234 5th Street", "Charlotte, NC 98765");
FillRow(oDataDoc, 4, "Brian", "Valentine",
"12348 78th Street Apt. 214",
"Lubbock, TX 25874");
FillRow(oDataDoc, 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
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...
8
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...
9
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...
6
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: ...
4
by: lesperancer | last post by:
I have 3 tables (office97) tblQuote quoteNbr tblDetails ( quote : 1 <-> M: quoteDetails) quoteNbr detailLine product value
5
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...
1
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...
0
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...
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!)...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.