Reply
 
Thread Tools Display Modes
  #1   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Che Che is offline
external usenet poster
 
Posts: 2
Default Mail Merge Word 2003, VB.NET 2008, CreateDataSource

Hi there,

I am trying to programmatically create an .ODC in my application and assign
it to a template for mail merge.
So far I have recorded a macro setting the .ODC up and cut and paste the
macro code into my application:

myDoc.MailMerge.OpenDataSource(Name:= _
"C:\Documents and Settings\cb\My Documents\My Data
Sources\RRS-MSSQL-DEV SUPPORT ctrl_users.odc" _
, ConfirmConversions:=False, ReadOnly:=False, LinkToSource:=True, _
AddToRecentFiles:=False, PasswordDocument:="", PasswordTemplate:="", _
WritePasswordDocument:="", WritePasswordTemplate:="", Revert:=False, _
Format:=WdOpenFormat.wdOpenFormatAuto, Connection:= _
"Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security
Info=True;Initial Catalog=SUPPORT;Data Source=RCS-MSSQL-DEV;Use Procedure for
Prepare=1;Auto Translate=True;Packet Size=4096;Workstation ID=CLYD42J;Use
Encryption for Data=False;Tag with column" _
, SQLStatement:="SELECT * FROM ""ctrl_users""", SQLStatement1:="", _
SubType:=WdMergeSubType.wdMergeSubTypeOther)

This isn't working like it does in Word itself. I only have 2 database
fields after the datasource is opened - M_1 and M! When I complete this macro
in Word itself, I have access to all the correct fields.

Any help would be appreciated. Thanks in advance!
  #2   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Peter Jamieson Peter Jamieson is offline
external usenet poster
 
Posts: 4,582
Default Mail Merge Word 2003, VB.NET 2008, CreateDataSource

I only have 2 database
fields after the datasource is opened - M_1 and M


NB this is typical behaviour when Word cannot connect to the real data
source via a .odc. The question is what's preventing it in this case.

What I was not completely sure about from your description is whether you
have managed to get the recorded macro to work in Word VBA, or whether you
can only make the connection when you set it up manually, and also whether
you are using exactly the same .odc in all your tests.

I cannot see anything obviously wrong with your OpenDataSource statement
except that the Connection string is truncated (that's something that Word
gets wrong) and that may or may not cause a problem.

In VBA, I would try one of the following:

If your .odc file specifies the table or view that you need, try...

myDoc.MailMerge.OpenDataSource _
Name:="C:\Documents and Settings\cb\My Documents\My Data
Sources\RRS-MSSQL-DEV SUPPORT ctrl_users.odc", _
Connection:="", _
SQLStatement:="", _
SubType:=wdMergeSubTypeOther

(you should not need any of the other stuff, and you may be able to get away
with just the Name parameter).


Or you can try the following, even with a completely empty .odc file:

myDoc.MailMerge.OpenDataSource _
Name:="C:\Documents and Settings\cb\My Documents\My Data
Sources\RRS-MSSQL-DEV SUPPORT ctrl_users.odc", _
Connection:="Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security
Info=False;Initial Catalog=SUPPORT;" _
& "Data Source=RCS-MSSQL-DEV;", _
SQLStatement:="SELECT * FROM [ctrl_users]", _
SubType:=wdMergeSubTypeOther

If the problem is that VBA connects OK, but the connection is not made when
you use the equivalent code in VBA.NET, that's probably not going to be
enough.

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

"che" wrote in message
...
Hi there,

I am trying to programmatically create an .ODC in my application and
assign
it to a template for mail merge.
So far I have recorded a macro setting the .ODC up and cut and paste the
macro code into my application:

myDoc.MailMerge.OpenDataSource(Name:= _
"C:\Documents and Settings\cb\My Documents\My Data
Sources\RRS-MSSQL-DEV SUPPORT ctrl_users.odc" _
, ConfirmConversions:=False, ReadOnly:=False, LinkToSource:=True, _
AddToRecentFiles:=False, PasswordDocument:="",
PasswordTemplate:="", _
WritePasswordDocument:="", WritePasswordTemplate:="",
Revert:=False, _
Format:=WdOpenFormat.wdOpenFormatAuto, Connection:= _
"Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security
Info=True;Initial Catalog=SUPPORT;Data Source=RCS-MSSQL-DEV;Use Procedure
for
Prepare=1;Auto Translate=True;Packet Size=4096;Workstation ID=CLYD42J;Use
Encryption for Data=False;Tag with column" _
, SQLStatement:="SELECT * FROM ""ctrl_users""", SQLStatement1:="",
_
SubType:=WdMergeSubType.wdMergeSubTypeOther)

This isn't working like it does in Word itself. I only have 2 database
fields after the datasource is opened - M_1 and M! When I complete this
macro
in Word itself, I have access to all the correct fields.

Any help would be appreciated. Thanks in advance!


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
Change January 1, 2008 to 01/01/2008 automatically in a form Lorraine Microsoft Word Help 3 August 20th 08 08:45 PM
Convesion of Mac Word 2008 to PC Word 2003 Sharad Microsoft Word Help 0 April 15th 08 06:33 PM
how can I stop word 2003 configuring Acad 2008 at start up ppriem Microsoft Word Help 1 August 24th 07 10:50 AM
Word 2003 pulls up my mail merge template, but doesn't complete the merge into a new Form Letter 1 Sean Steele Mailmerge 1 April 12th 07 11:04 PM
Exchange 2003 - Outlook 2003 - Word 2003 mail merge Micheline Mailmerge 1 December 2nd 04 11:51 AM


All times are GMT +1. The time now is 05:01 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"