Reply
 
Thread Tools Display Modes
  #1   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Tony Tony is offline
external usenet poster
 
Posts: 79
Default Automating MailMerge via C# problems

Hi All,
I was wondering if you could help me out. I am calling mailmerge through a
sql call in c#; however, some of the fields do not display when the document
is displayed. Any suggestion on what I should be looking at.... I used the
same query while manually creating a mail merge and that worked...therefore,
I concluded that it couldnt be on the db end....

thanks
  #2   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Peter Jamieson Peter Jamieson is offline
external usenet poster
 
Posts: 4,582
Default Automating MailMerge via C# problems

If the data source is SQL Server, the "rogue fields" have Unicode data
types, you are using Word 2002 or later, and you're using OpenDataSource,
then the chances are that
a. when you connect manually, you are using OLE DB
b. when you connect via c#, you are inadvertently using ODBC

That's 4 "if"s - if you can post the strings you are passing to
OpenDataSource for the name, connection and sqlstatement parameters it might
be a bit easier to consider what might be going wrong. Also useful to know
which version of Word and what the data source is.

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

"Tony" wrote in message
...
Hi All,
I was wondering if you could help me out. I am calling mailmerge through a
sql call in c#; however, some of the fields do not display when the
document
is displayed. Any suggestion on what I should be looking at.... I used the
same query while manually creating a mail merge and that
worked...therefore,
I concluded that it couldnt be on the db end....

thanks


  #3   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Tony Tony is offline
external usenet poster
 
Posts: 79
Default Automating MailMerge via C# problems

Hi,
I am using Word 2003.
Here is the connection string I use:
"DSN=csasearch;DATABASE=csasearch;uid=sa;pwd=cobov ubu;", str,
"C:\Contract.doc"

the sql statement is

select * from vw1

----------------------
the code is:
dsName = Nothing
dsFormat = System.Type.Missing
dsConfirmConversion = System.Type.Missing
dsReadOnly = System.Type.Missing
dsLinkToSource = System.Type.Missing
dsAddToRecentFiles = System.Type.Missing
dsPasswordDocument = System.Type.Missing
dsPasswordTemplate = System.Type.Missing
dsRevert = False
dsWritePasswordDocument = System.Type.Missing
dsWritePasswordTemplate = System.Type.Missing

dsConnection = connection
dsSQLStatement = sql

dsSQLStatement1 = System.Type.Missing
dsOpenExclusive = System.Type.Missing
dsSubType = Word.WdMergeSubType.wdMergeSubTypeOLEDBText

wordDoc.MailMerge.OpenDataSource("", dsFormat, dsConfirmConversion,
dsReadOnly, dsLinkToSource, dsAddToRecentFiles, dsPasswordDocument,
dsPasswordTemplate, dsRevert, dsWritePasswordDocument, dsPasswordTemplate,
dsConnection, dsSQLStatement, dsSQLStatement1, dsOpenExclusive, dsSubType)

Thanks for your response

  #4   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Peter Jamieson Peter Jamieson is offline
external usenet poster
 
Posts: 4,582
Default Automating MailMerge via C# problems

As soon as you specify a DSN Word will use ODBC and you will lose Unicode
data. Even if Word happens to use the OLE Db provider for ODBC data sources,
I think you will lose the Unicode data (if that is what the problem is). I
am slightly cautious because you say it works when you connect manually
(i.e. I think you would have to use a .udl or .odc, not a DSN, for that to
work, but perhaps I am wrong).

The only way to use OLE DB (which should retain Unicode data) is to specify
a .udl or .odc file in the Name parameter. You can either use a valid .udl
or .odc that specifies the necessary connection information, or you can use
an empty .odc or .udl (e.g. create a Notepad file and put no text in it) and
specify all the connection information in the Connection parameter. But
AFAIK there is no way to avoid having that .udl or .odc. If you are
concerned about having to distribute that file, you can consider putting it
on a network drive that ican't locate the .udl or .odc at a URL such as
http:// or ftp://

Anyway, if you go the "blank .udl/.odc" route, what you probably need is a
connection string like:

Provider=SQLOLEDB.1;Persist Security Info=False;User
ID=sa;Password=cobovubu;Initial Catalog=csasearch;Data Source=put the name
of the server machine here

You may need Persist Security Info=True

That uses the old SQL Server OLE DB provider. For the new one ("SQL Native
Client"), try using

Provider=SQLNCLI.1

(as far as I know most of the other parameters are the same). however,
whenever I have tried to use Word with the new "Native Client" and with a
logon and password rather than Windows Integrated Security, I have failed. I
don't think this is just down to the additional security configuration stuff
in newer versions of SQL Server, but maybe you will not have to face that
problem.)

Finally,

dsSubType = Word.WdMergeSubType.wdMergeSubTypeOLEDBText

is not the right subtype - you will probably be better off using
System.Type.Missing

I think this OLEDBText subtype is intended to specify that you want to open
a delimited text file using OLE DB rather than an internal converter or
ODBC, but I've never been able to verify that (The "Subtype" parameter isn't
exactly well-documented :-( )

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

"Tony" wrote in message
...
Hi,
I am using Word 2003.
Here is the connection string I use:
"DSN=csasearch;DATABASE=csasearch;uid=sa;pwd=cobov ubu;", str,
"C:\Contract.doc"

the sql statement is

select * from vw1

----------------------
the code is:
dsName = Nothing
dsFormat = System.Type.Missing
dsConfirmConversion = System.Type.Missing
dsReadOnly = System.Type.Missing
dsLinkToSource = System.Type.Missing
dsAddToRecentFiles = System.Type.Missing
dsPasswordDocument = System.Type.Missing
dsPasswordTemplate = System.Type.Missing
dsRevert = False
dsWritePasswordDocument = System.Type.Missing
dsWritePasswordTemplate = System.Type.Missing

dsConnection = connection
dsSQLStatement = sql

dsSQLStatement1 = System.Type.Missing
dsOpenExclusive = System.Type.Missing
dsSubType = Word.WdMergeSubType.wdMergeSubTypeOLEDBText

wordDoc.MailMerge.OpenDataSource("", dsFormat, dsConfirmConversion,
dsReadOnly, dsLinkToSource, dsAddToRecentFiles, dsPasswordDocument,
dsPasswordTemplate, dsRevert, dsWritePasswordDocument, dsPasswordTemplate,
dsConnection, dsSQLStatement, dsSQLStatement1, dsOpenExclusive, dsSubType)

Thanks for your response


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
Automating Mailmerge using CSV results in squares / Japanese characters Guabble Mailmerge 3 August 16th 07 03:11 PM
Automating MailMerge tony Mailmerge 1 December 19th 05 09:18 PM
mailmerge problems Mim Mailmerge 1 August 24th 05 06:51 PM
Problems with Mailmerge and odc hals left Mailmerge 0 August 9th 05 08:27 PM
Detecting Wrong MergeFields while automating MailMerge Christof Nordiek Mailmerge 1 April 29th 05 08:48 AM


All times are GMT +1. The time now is 07:57 PM.

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"