Reply
 
Thread Tools Display Modes
  #1   Report Post  
Posted to microsoft.public.word.mailmerge.fields
ChrisRS ChrisRS is offline
external usenet poster
 
Posts: 4
Default c# mail merge only showing date fields in merge

I am using C# with Visual Studio 2005 with Office 2003 mail merging data from
an SQL database.

The merge works successfully using various templates and various SQL queries
and creates the final merged document. However only fields which are datetime
fields are outputted and text fields are left blank in the Word doc. The
fields in the query do contain data and no errors are produced.

Any ideas on what can be causing this?

A small section of the merge code is shown below (if that helps)

Cheers
Chris

-----------------------

wrdApp = new Microsoft.Office.Interop.Word.ApplicationClass();
wrdApp.Visible = true;
oDataDoc = wrdApp.Documents.Add(ref oName, ref oFalse, ref oMissing, ref
oMissing);
oDataDoc.Activate();
wrdMailMerge = oDataDoc.MailMerge;
wrdMailMerge.HighlightMergeFields = true;
oQuery = stat.Text; // stat field contains SQL query

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);
// i think the above line of code is causing the problem

wrdMailMerge.SuppressBlankLines = true;
wrdMailMerge.Destination =
Microsoft.Office.Interop.Word.WdMailMergeDestinati on.wdSendToNewDocument;
wrdMailMerge.Execute(ref oFalse);
oDataDoc.Close(ref oFalse, ref oMissing, ref oMissing);

------------------
  #2   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Peter Jamieson Peter Jamieson is offline
external usenet poster
 
Posts: 4,582
Default c# mail merge only showing date fields in merge

If it's a SQL Server database, then the problem is likely to be that you
have Unicode format fields in your database, and the OpenDataSource you are
using is likely to cause Word to open a connection using ODBC. Either ODBC
does not pass the Unicode data through or WOrd+ODBC doesn't. If that's the
case, what you really need to do is to set up a .ODC or .UDL file that
contains the connection infromation for your database and specify that in
the Name parameter of the method call. If you can't do that, the only ways
to live with this limitation are either to change the database field types
to be non-unicode, or use a view (or other technique) and the CAST/CONVERT
functions to convert to non-Unicode data.

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

"ChrisRS" wrote in message
...
I am using C# with Visual Studio 2005 with Office 2003 mail merging data
from
an SQL database.

The merge works successfully using various templates and various SQL
queries
and creates the final merged document. However only fields which are
datetime
fields are outputted and text fields are left blank in the Word doc. The
fields in the query do contain data and no errors are produced.

Any ideas on what can be causing this?

A small section of the merge code is shown below (if that helps)

Cheers
Chris

-----------------------

wrdApp = new Microsoft.Office.Interop.Word.ApplicationClass();
wrdApp.Visible = true;
oDataDoc = wrdApp.Documents.Add(ref oName, ref oFalse, ref oMissing, ref
oMissing);
oDataDoc.Activate();
wrdMailMerge = oDataDoc.MailMerge;
wrdMailMerge.HighlightMergeFields = true;
oQuery = stat.Text; // stat field contains SQL query

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);
// i think the above line of code is causing the problem

wrdMailMerge.SuppressBlankLines = true;
wrdMailMerge.Destination =
Microsoft.Office.Interop.Word.WdMailMergeDestinati on.wdSendToNewDocument;
wrdMailMerge.Execute(ref oFalse);
oDataDoc.Close(ref oFalse, ref oMissing, ref oMissing);

------------------


  #3   Report Post  
Posted to microsoft.public.word.mailmerge.fields
ChrisRS ChrisRS is offline
external usenet poster
 
Posts: 4
Default c# mail merge only showing date fields in merge

Thanks for that.... I will look into it.

Cheers
Chris

"Peter Jamieson" wrote:

If it's a SQL Server database, then the problem is likely to be that you
have Unicode format fields in your database, and the OpenDataSource you are
using is likely to cause Word to open a connection using ODBC. Either ODBC
does not pass the Unicode data through or WOrd+ODBC doesn't. If that's the
case, what you really need to do is to set up a .ODC or .UDL file that
contains the connection infromation for your database and specify that in
the Name parameter of the method call. If you can't do that, the only ways
to live with this limitation are either to change the database field types
to be non-unicode, or use a view (or other technique) and the CAST/CONVERT
functions to convert to non-Unicode data.

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

"ChrisRS" wrote in message
...
I am using C# with Visual Studio 2005 with Office 2003 mail merging data
from
an SQL database.

The merge works successfully using various templates and various SQL
queries
and creates the final merged document. However only fields which are
datetime
fields are outputted and text fields are left blank in the Word doc. The
fields in the query do contain data and no errors are produced.

Any ideas on what can be causing this?

A small section of the merge code is shown below (if that helps)

Cheers
Chris

-----------------------

wrdApp = new Microsoft.Office.Interop.Word.ApplicationClass();
wrdApp.Visible = true;
oDataDoc = wrdApp.Documents.Add(ref oName, ref oFalse, ref oMissing, ref
oMissing);
oDataDoc.Activate();
wrdMailMerge = oDataDoc.MailMerge;
wrdMailMerge.HighlightMergeFields = true;
oQuery = stat.Text; // stat field contains SQL query

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);
// i think the above line of code is causing the problem

wrdMailMerge.SuppressBlankLines = true;
wrdMailMerge.Destination =
Microsoft.Office.Interop.Word.WdMailMergeDestinati on.wdSendToNewDocument;
wrdMailMerge.Execute(ref oFalse);
oDataDoc.Close(ref oFalse, ref oMissing, ref oMissing);

------------------



  #4   Report Post  
Posted to microsoft.public.word.mailmerge.fields
ChrisRS ChrisRS is offline
external usenet poster
 
Posts: 4
Default c# mail merge only showing date fields in merge

oki....

I have created a UDL file that will connect to the server.... however I am
unable to connect the UDL file to the C# code.

The code i am using is :-

....
Object oConnection = new OleDbConnection("File Name = c:\\test.udl");
....
....
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);
....

And error is....
Type mismatch. (Exception from HRESULT: 0x80020005 (DISP_E_TYPEMISMATCH))

I presume the mismatch is with the connection object but not sure were I am
going wrong.

Any help please?

Many thanks
Chris


"ChrisRS" wrote:

Thanks for that.... I will look into it.

Cheers
Chris

"Peter Jamieson" wrote:

If it's a SQL Server database, then the problem is likely to be that you
have Unicode format fields in your database, and the OpenDataSource you are
using is likely to cause Word to open a connection using ODBC. Either ODBC
does not pass the Unicode data through or WOrd+ODBC doesn't. If that's the
case, what you really need to do is to set up a .ODC or .UDL file that
contains the connection infromation for your database and specify that in
the Name parameter of the method call. If you can't do that, the only ways
to live with this limitation are either to change the database field types
to be non-unicode, or use a view (or other technique) and the CAST/CONVERT
functions to convert to non-Unicode data.

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

"ChrisRS" wrote in message
...
I am using C# with Visual Studio 2005 with Office 2003 mail merging data
from
an SQL database.

The merge works successfully using various templates and various SQL
queries
and creates the final merged document. However only fields which are
datetime
fields are outputted and text fields are left blank in the Word doc. The
fields in the query do contain data and no errors are produced.

Any ideas on what can be causing this?

A small section of the merge code is shown below (if that helps)

Cheers
Chris

-----------------------

wrdApp = new Microsoft.Office.Interop.Word.ApplicationClass();
wrdApp.Visible = true;
oDataDoc = wrdApp.Documents.Add(ref oName, ref oFalse, ref oMissing, ref
oMissing);
oDataDoc.Activate();
wrdMailMerge = oDataDoc.MailMerge;
wrdMailMerge.HighlightMergeFields = true;
oQuery = stat.Text; // stat field contains SQL query

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);
// i think the above line of code is causing the problem

wrdMailMerge.SuppressBlankLines = true;
wrdMailMerge.Destination =
Microsoft.Office.Interop.Word.WdMailMergeDestinati on.wdSendToNewDocument;
wrdMailMerge.Execute(ref oFalse);
oDataDoc.Close(ref oFalse, ref oMissing, ref oMissing);

------------------



  #5   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Peter Jamieson Peter Jamieson is offline
external usenet poster
 
Posts: 4,582
Default c# mail merge only showing date fields in merge

Set the name parameter of the OpenDataSOurce to be the pathname of the
..odc/.udl, e.g.

wrdMailMerge.OpenDataSource("c:\\test.udl", 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);

Typically you would not need to provide an Connection parameter (the info.
is in the .udl) or any particular SubType (i.e. you can probably leave that
as oMissing) but you will need a Query and you may find that you have to
alias any table names it contains, even though it may not be syntactically
necessary.
--
Peter Jamieson
http://tips.pjmsn.me.uk

"ChrisRS" wrote in message
...
oki....

I have created a UDL file that will connect to the server.... however I am
unable to connect the UDL file to the C# code.

The code i am using is :-

...
Object oConnection = new OleDbConnection("File Name = c:\\test.udl");
...
...
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);
...

And error is....
Type mismatch. (Exception from HRESULT: 0x80020005 (DISP_E_TYPEMISMATCH))

I presume the mismatch is with the connection object but not sure were I
am
going wrong.

Any help please?

Many thanks
Chris


"ChrisRS" wrote:

Thanks for that.... I will look into it.

Cheers
Chris

"Peter Jamieson" wrote:

If it's a SQL Server database, then the problem is likely to be that
you
have Unicode format fields in your database, and the OpenDataSource you
are
using is likely to cause Word to open a connection using ODBC. Either
ODBC
does not pass the Unicode data through or WOrd+ODBC doesn't. If that's
the
case, what you really need to do is to set up a .ODC or .UDL file that
contains the connection infromation for your database and specify that
in
the Name parameter of the method call. If you can't do that, the only
ways
to live with this limitation are either to change the database field
types
to be non-unicode, or use a view (or other technique) and the
CAST/CONVERT
functions to convert to non-Unicode data.

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

"ChrisRS" wrote in message
...
I am using C# with Visual Studio 2005 with Office 2003 mail merging
data
from
an SQL database.

The merge works successfully using various templates and various SQL
queries
and creates the final merged document. However only fields which are
datetime
fields are outputted and text fields are left blank in the Word doc.
The
fields in the query do contain data and no errors are produced.

Any ideas on what can be causing this?

A small section of the merge code is shown below (if that helps)

Cheers
Chris

-----------------------

wrdApp = new Microsoft.Office.Interop.Word.ApplicationClass();
wrdApp.Visible = true;
oDataDoc = wrdApp.Documents.Add(ref oName, ref oFalse, ref oMissing,
ref
oMissing);
oDataDoc.Activate();
wrdMailMerge = oDataDoc.MailMerge;
wrdMailMerge.HighlightMergeFields = true;
oQuery = stat.Text; // stat field contains SQL query

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);
// i think the above line of code is causing the problem

wrdMailMerge.SuppressBlankLines = true;
wrdMailMerge.Destination =
Microsoft.Office.Interop.Word.WdMailMergeDestinati on.wdSendToNewDocument;
wrdMailMerge.Execute(ref oFalse);
oDataDoc.Close(ref oFalse, ref oMissing, ref oMissing);

------------------





  #6   Report Post  
Posted to microsoft.public.word.mailmerge.fields
ChrisRS ChrisRS is offline
external usenet poster
 
Posts: 4
Default c# mail merge only showing date fields in merge

Many thanks... it is all sorted

"ChrisRS" wrote:

I am using C# with Visual Studio 2005 with Office 2003 mail merging data from
an SQL database.

The merge works successfully using various templates and various SQL queries
and creates the final merged document. However only fields which are datetime
fields are outputted and text fields are left blank in the Word doc. The
fields in the query do contain data and no errors are produced.

Any ideas on what can be causing this?

A small section of the merge code is shown below (if that helps)

Cheers
Chris

-----------------------

wrdApp = new Microsoft.Office.Interop.Word.ApplicationClass();
wrdApp.Visible = true;
oDataDoc = wrdApp.Documents.Add(ref oName, ref oFalse, ref oMissing, ref
oMissing);
oDataDoc.Activate();
wrdMailMerge = oDataDoc.MailMerge;
wrdMailMerge.HighlightMergeFields = true;
oQuery = stat.Text; // stat field contains SQL query

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);
// i think the above line of code is causing the problem

wrdMailMerge.SuppressBlankLines = true;
wrdMailMerge.Destination =
Microsoft.Office.Interop.Word.WdMailMergeDestinati on.wdSendToNewDocument;
wrdMailMerge.Execute(ref oFalse);
oDataDoc.Close(ref oFalse, ref oMissing, ref oMissing);

------------------

Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Mail Merge Date fields Fi Mailmerge 1 June 5th 07 03:54 PM
Hidden merge fields not showing up Brian Beck Mailmerge 1 June 1st 07 06:02 AM
Outlook Fields not showing up in Mail Merge Jason Dove Mailmerge 1 May 24th 07 07:07 PM
Using mail merge date fields in headers Tina Mailmerge 4 March 22nd 07 03:26 PM
mail merge not showing fields from outlook contacts Drew Mailmerge 2 January 27th 05 05:57 AM


All times are GMT +1. The time now is 04:28 AM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"