A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Word » Mailmerge
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Mail Merge to SQL Server without using an external ODC



 
 
Thread Tools Display Modes
  #1  
Old November 21st, 2006, 07:58 PM posted to microsoft.public.word.mailmerge.fields
Graham
external usenet poster
 
Posts: 2
Default Mail Merge to SQL Server without using an external ODC

Is there any way to embed the SQL Server connection information right
into a Word document? I'd like to be able to e-mail the document to
others within the organization without having to navigate them through
the process of creating a data source. (They all have access to the SQL
server, of course.)

Thanks,

g.

  #2  
Old November 24th, 2006, 03:38 PM posted to microsoft.public.word.mailmerge.fields
Cindy M.
external usenet poster
 
Posts: 2,428
Default Mail Merge to SQL Server without using an external ODC

Hi Graham,

Is there any way to embed the SQL Server connection information right
into a Word document? I'd like to be able to e-mail the document to
others within the organization without having to navigate them through
the process of creating a data source. (They all have access to the SQL
server, of course.)

Which version of Word are we discussing? And do your systems have an ODBC
driver for SQL Server installed?

I think it can't be done for OLE DB, as this also requires an external
*.odc file. ODBC can probably do it. And a macro that links the data
source when the file opens could probably work.

Another possibility (and it's what MSFT had in mind when they designed
the interface) would be to distribute the *.odc file for the connection
to everyone's "My Data Source" folder.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :-)

  #3  
Old November 24th, 2006, 06:35 PM posted to microsoft.public.word.mailmerge.fields
Graham
external usenet poster
 
Posts: 2
Default Mail Merge to SQL Server without using an external ODC

Cindy M.
wrote:
Hi Graham,

Is there any way to embed the SQL Server connection information right
into a Word document?


Which version of Word are we discussing? And do your systems have an ODBC
driver for SQL Server installed?

I think it can't be done for OLE DB, as this also requires an external
*.odc file. ODBC can probably do it. And a macro that links the data
source when the file opens could probably work.

Another possibility (and it's what MSFT had in mind when they designed
the interface) would be to distribute the *.odc file for the connection
to everyone's "My Data Source" folder.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org


Word 2003, and all Microsoft systems have the SQL ODBC driver
installed.

The distribution path you describe would require an installer, which is
a heck of a lot of trouble to get a 25-character connection string down
to the users' machines. Honestly, I think this is another of those
situations where Microsoft didn't have *anything* in mind.

g.

  #4  
Old November 30th, 2006, 09:37 AM posted to microsoft.public.word.mailmerge.fields
Peter Jamieson
external usenet poster
 
Posts: 4,550
Default Mail Merge to SQL Server without using an external ODC

Did you work out how to do the ODBC connection?

Honestly, I think this is another of those
situations where Microsoft didn't have *anything* in mind.


I certainly don't understand why they insist that you have an external
object of some kind and don't allow DSN-less and ODC-less connections,
unless of course they were
a. worried that the end result would be loads of .doc files with embedded
plain text login/password info.
(but if you're using SQL Server integrated security that's wouldn't be an
issue anyway)
or
b. worried that then people would be able to distibute their merge
qapplications reasonably easily :-)

Peter Jamieson

"Graham" wrote in message
oups.com...
Cindy M.
wrote:
Hi Graham,

Is there any way to embed the SQL Server connection information right
into a Word document?


Which version of Word are we discussing? And do your systems have an ODBC
driver for SQL Server installed?

I think it can't be done for OLE DB, as this also requires an external
*.odc file. ODBC can probably do it. And a macro that links the data
source when the file opens could probably work.

Another possibility (and it's what MSFT had in mind when they designed
the interface) would be to distribute the *.odc file for the connection
to everyone's "My Data Source" folder.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org


Word 2003, and all Microsoft systems have the SQL ODBC driver
installed.

The distribution path you describe would require an installer, which is
a heck of a lot of trouble to get a 25-character connection string down
to the users' machines. Honestly, I think this is another of those
situations where Microsoft didn't have *anything* in mind.

g.



  #5  
Old February 6th, 2007, 04:38 PM posted to microsoft.public.word.mailmerge.fields
Todd K.
external usenet poster
 
Posts: 48
Default Mail Merge to SQL Server without using an external ODC

Peter -

I have a similar situation. I have code that works when the source is an
Access table (see below), but when the source changed to SQL Server it quit
working. Is there a different protocol for SQL Server or is it probably in
the routing?:

Private Sub Document_Open()

Me.MailMerge.OpenDataSource _
Name:="I:\Applications\Databases\ProjectOne.adp", _
LinkToSource:=True, _
Connection:="TABLE TblAmendment_Ren", _
SQLStatement:="SELECT * FROM [TblAmendment_Ren]"
Me.MailMerge.Destination = wdSendToNewDocument
Me.MailMerge.Execute
Windows(Me).Close wdDoNotSaveChanges

End Sub

"Peter Jamieson" wrote:

Did you work out how to do the ODBC connection?

Honestly, I think this is another of those
situations where Microsoft didn't have *anything* in mind.


I certainly don't understand why they insist that you have an external
object of some kind and don't allow DSN-less and ODC-less connections,
unless of course they were
a. worried that the end result would be loads of .doc files with embedded
plain text login/password info.
(but if you're using SQL Server integrated security that's wouldn't be an
issue anyway)
or
b. worried that then people would be able to distibute their merge
qapplications reasonably easily :-)

Peter Jamieson

"Graham" wrote in message
oups.com...
Cindy M.
wrote:
Hi Graham,

Is there any way to embed the SQL Server connection information right
into a Word document?


Which version of Word are we discussing? And do your systems have an ODBC
driver for SQL Server installed?

I think it can't be done for OLE DB, as this also requires an external
*.odc file. ODBC can probably do it. And a macro that links the data
source when the file opens could probably work.

Another possibility (and it's what MSFT had in mind when they designed
the interface) would be to distribute the *.odc file for the connection
to everyone's "My Data Source" folder.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org


Word 2003, and all Microsoft systems have the SQL ODBC driver
installed.

The distribution path you describe would require an installer, which is
a heck of a lot of trouble to get a 25-character connection string down
to the users' machines. Honestly, I think this is another of those
situations where Microsoft didn't have *anything* in mind.

g.




  #6  
Old February 6th, 2007, 05:46 PM posted to microsoft.public.word.mailmerge.fields
Peter Jamieson
external usenet poster
 
Posts: 4,550
Default Mail Merge to SQL Server without using an external ODC

Which version of Word?

At the moment I'd guess your code is using DDE to get the data (i.e. Access
will open and get the data).

When you say that the source changed to SQl Server do you mean that the
underlying data moved to SQL Server (and that you still have linked tables
in your .adp) or that the whole thing moved to SQL Server?

For starters, to connect directly to SQL Server you need either
a. a suitable ODBC DSN (either "machine" DSN or .dsn file) or
b. a suitable OLE DB .udl file or
c. a suitable OLE DB .odc file

I can go into the details if necessary but maybe that will take you a step
further. As a rule, an OLE DB connection is advisable, and essential if your
SQl Server database has Unicode fields in it (which it almost certainly will
have if it was created from an Access project using the Upsizing wizard.

Connecting to SQL Server tables and views should be straightforward,
security issues permitting, but connecting to stored procedures/stored
functions is another matter.

Peter Jamieson

"Todd K." wrote in message
news
Peter -

I have a similar situation. I have code that works when the source is an
Access table (see below), but when the source changed to SQL Server it
quit
working. Is there a different protocol for SQL Server or is it probably
in
the routing?:

Private Sub Document_Open()

Me.MailMerge.OpenDataSource _
Name:="I:\Applications\Databases\ProjectOne.adp", _
LinkToSource:=True, _
Connection:="TABLE TblAmendment_Ren", _
SQLStatement:="SELECT * FROM [TblAmendment_Ren]"
Me.MailMerge.Destination = wdSendToNewDocument
Me.MailMerge.Execute
Windows(Me).Close wdDoNotSaveChanges

End Sub

"Peter Jamieson" wrote:

Did you work out how to do the ODBC connection?

Honestly, I think this is another of those
situations where Microsoft didn't have *anything* in mind.


I certainly don't understand why they insist that you have an external
object of some kind and don't allow DSN-less and ODC-less connections,
unless of course they were
a. worried that the end result would be loads of .doc files with
embedded
plain text login/password info.
(but if you're using SQL Server integrated security that's wouldn't be an
issue anyway)
or
b. worried that then people would be able to distibute their merge
qapplications reasonably easily :-)

Peter Jamieson

"Graham" wrote in message
oups.com...
Cindy M.
wrote:
Hi Graham,

Is there any way to embed the SQL Server connection information
right
into a Word document?

Which version of Word are we discussing? And do your systems have an
ODBC
driver for SQL Server installed?

I think it can't be done for OLE DB, as this also requires an external
*.odc file. ODBC can probably do it. And a macro that links the data
source when the file opens could probably work.

Another possibility (and it's what MSFT had in mind when they designed
the interface) would be to distribute the *.odc file for the
connection
to everyone's "My Data Source" folder.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

Word 2003, and all Microsoft systems have the SQL ODBC driver
installed.

The distribution path you describe would require an installer, which is
a heck of a lot of trouble to get a 25-character connection string down
to the users' machines. Honestly, I think this is another of those
situations where Microsoft didn't have *anything* in mind.

g.






  #7  
Old February 6th, 2007, 06:21 PM posted to microsoft.public.word.mailmerge.fields
Todd K.
external usenet poster
 
Posts: 48
Default Mail Merge to SQL Server without using an external ODC

1) Word 2003
2) The whole thing will be moved to SQL Server. So much needed to be
upgraded and changed from the current Access DB that we decided to build a
SQL Server project from scratch. Right now it is on my CPU as a MySQL
project, but upon completion we will move it to a separate server. The Word
documents were rebuilt as Merge documents "linked" to the SQL tables, and
that worked great from my computer but not from anyone else's. So I figured
how to use the code below on the current Access database allowing everyone to
utilize them from their computers. When I essentially just changed the code
in the OpenDataSource, it can't seem to find the SQL table
3) I just want to connect to a SQL Server table, no stored procedures.

"Peter Jamieson" wrote:

Which version of Word?

At the moment I'd guess your code is using DDE to get the data (i.e. Access
will open and get the data).

When you say that the source changed to SQl Server do you mean that the
underlying data moved to SQL Server (and that you still have linked tables
in your .adp) or that the whole thing moved to SQL Server?

For starters, to connect directly to SQL Server you need either
a. a suitable ODBC DSN (either "machine" DSN or .dsn file) or
b. a suitable OLE DB .udl file or
c. a suitable OLE DB .odc file

I can go into the details if necessary but maybe that will take you a step
further. As a rule, an OLE DB connection is advisable, and essential if your
SQl Server database has Unicode fields in it (which it almost certainly will
have if it was created from an Access project using the Upsizing wizard.

Connecting to SQL Server tables and views should be straightforward,
security issues permitting, but connecting to stored procedures/stored
functions is another matter.

Peter Jamieson

"Todd K." wrote in message
news
Peter -

I have a similar situation. I have code that works when the source is an
Access table (see below), but when the source changed to SQL Server it
quit
working. Is there a different protocol for SQL Server or is it probably
in
the routing?:

Private Sub Document_Open()

Me.MailMerge.OpenDataSource _
Name:="I:\Applications\Databases\ProjectOne.adp", _
LinkToSource:=True, _
Connection:="TABLE TblAmendment_Ren", _
SQLStatement:="SELECT * FROM [TblAmendment_Ren]"
Me.MailMerge.Destination = wdSendToNewDocument
Me.MailMerge.Execute
Windows(Me).Close wdDoNotSaveChanges

End Sub

"Peter Jamieson" wrote:

Did you work out how to do the ODBC connection?

Honestly, I think this is another of those
situations where Microsoft didn't have *anything* in mind.

I certainly don't understand why they insist that you have an external
object of some kind and don't allow DSN-less and ODC-less connections,
unless of course they were
a. worried that the end result would be loads of .doc files with
embedded
plain text login/password info.
(but if you're using SQL Server integrated security that's wouldn't be an
issue anyway)
or
b. worried that then people would be able to distibute their merge
qapplications reasonably easily :-)

Peter Jamieson

"Graham" wrote in message
oups.com...
Cindy M.
wrote:
Hi Graham,

Is there any way to embed the SQL Server connection information
right
into a Word document?

Which version of Word are we discussing? And do your systems have an
ODBC
driver for SQL Server installed?

I think it can't be done for OLE DB, as this also requires an external
*.odc file. ODBC can probably do it. And a macro that links the data
source when the file opens could probably work.

Another possibility (and it's what MSFT had in mind when they designed
the interface) would be to distribute the *.odc file for the
connection
to everyone's "My Data Source" folder.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

Word 2003, and all Microsoft systems have the SQL ODBC driver
installed.

The distribution path you describe would require an installer, which is
a heck of a lot of trouble to get a 25-character connection string down
to the users' machines. Honestly, I think this is another of those
situations where Microsoft didn't have *anything* in mind.

g.







  #8  
Old February 6th, 2007, 06:55 PM posted to microsoft.public.word.mailmerge.fields
Peter Jamieson
external usenet poster
 
Posts: 4,550
Default Mail Merge to SQL Server without using an external ODC

The Word
documents were rebuilt as Merge documents "linked" to the SQL tables, and
that worked great from my computer but not from anyone else's.


If you did this using a .odc, then you would have to distribute the .odc to
the other systems, and the other users would obviously have to have the
necessary permissions for the tables/views they need to access. You would
probably also have to re-issue the OpenDataSource call, for exampel in an
AutoOpen macro.

If you're using SQl Server with Windows Integrated Security, you shouldn't
have too many problems in this area. If you're not, then
a. everything gets a lot more difficult, straight away
b. I'm not even sure you will be able to make it work at all if you are
using SQL Server 2005 and the new drivers/providers that come with it. I
haven't been able to do it with SQl Server security so far.

Also, you may need to consider

http://support.microsoft.com/kb/825765

However, when you use a .odc you currently have two choices:
a. have a .odc for each table or view you want to connect to, and specify
any query information in the SQLStatement and SQLStatement1 parameters in
Word's OpenDataSource method
b. use one completely empty .odc (i.e. an empty text file) and specify
everything you need in the OpenDataSource call.

It seems likely that distributing a set of solutions based on (b) is likely
to be easier than basing them on (a).

Let's suppose you head for (b). You still have to write that OpenDataSource
call and specify where that empty .odc is. I suppose there are two possible
solutions:
a. put an empty .odc in every user's My Data Sources folder, build the
complete pathname for that file for each user and use that
b. use a completely standard pathname, e.g. c:\myodcs\empty.odc , for
everyone. can't do much harm - it's just an empty file and all the necessary
security is handled elsewhere. I hope.

As for the OpenDataSource code, with an empty.odc you will probably need
something like

ActiveDocument.MailMerge.OpenDataSource _
Name:="c:\myodcs\empty.odc", _
Connection:="Provider=SQLOLEDB.1;Integrated Security=SSPI;" & _
"Persist Security Info=False;Initial Catalog=mydb;Data Source=myserver;"
_
SQLSatatement:="SELECT FROM ""mytable"", _
SubType:=wdMergeSubTypeOther

where "myserver" is the name of the server running your SQl Server database,
"mydb" is the name of the database you want to access and "mytable" is the
table or view from which you want to retrieve data.

You'll need a different Provider name for SQl Server 2005's native
provider...

See if that gets you any further.

Peter Jamieson

"Todd K." wrote in message
...
1) Word 2003
2) The whole thing will be moved to SQL Server. So much needed to be
upgraded and changed from the current Access DB that we decided to build a
SQL Server project from scratch. Right now it is on my CPU as a MySQL
project, but upon completion we will move it to a separate server. The
Word
documents were rebuilt as Merge documents "linked" to the SQL tables, and
that worked great from my computer but not from anyone else's. So I
figured
how to use the code below on the current Access database allowing everyone
to
utilize them from their computers. When I essentially just changed the
code
in the OpenDataSource, it can't seem to find the SQL table
3) I just want to connect to a SQL Server table, no stored procedures.

"Peter Jamieson" wrote:

Which version of Word?

At the moment I'd guess your code is using DDE to get the data (i.e.
Access
will open and get the data).

When you say that the source changed to SQl Server do you mean that the
underlying data moved to SQL Server (and that you still have linked
tables
in your .adp) or that the whole thing moved to SQL Server?

For starters, to connect directly to SQL Server you need either
a. a suitable ODBC DSN (either "machine" DSN or .dsn file) or
b. a suitable OLE DB .udl file or
c. a suitable OLE DB .odc file

I can go into the details if necessary but maybe that will take you a
step
further. As a rule, an OLE DB connection is advisable, and essential if
your
SQl Server database has Unicode fields in it (which it almost certainly
will
have if it was created from an Access project using the Upsizing wizard.

Connecting to SQL Server tables and views should be straightforward,
security issues permitting, but connecting to stored procedures/stored
functions is another matter.

Peter Jamieson

"Todd K." wrote in message
news
Peter -

I have a similar situation. I have code that works when the source is
an
Access table (see below), but when the source changed to SQL Server it
quit
working. Is there a different protocol for SQL Server or is it
probably
in
the routing?:

Private Sub Document_Open()

Me.MailMerge.OpenDataSource _
Name:="I:\Applications\Databases\ProjectOne.adp", _
LinkToSource:=True, _
Connection:="TABLE TblAmendment_Ren", _
SQLStatement:="SELECT * FROM [TblAmendment_Ren]"
Me.MailMerge.Destination = wdSendToNewDocument
Me.MailMerge.Execute
Windows(Me).Close wdDoNotSaveChanges

End Sub

"Peter Jamieson" wrote:

Did you work out how to do the ODBC connection?

Honestly, I think this is another of those
situations where Microsoft didn't have *anything* in mind.

I certainly don't understand why they insist that you have an external
object of some kind and don't allow DSN-less and ODC-less connections,
unless of course they were
a. worried that the end result would be loads of .doc files with
embedded
plain text login/password info.
(but if you're using SQL Server integrated security that's wouldn't be
an
issue anyway)
or
b. worried that then people would be able to distibute their merge
qapplications reasonably easily :-)

Peter Jamieson

"Graham" wrote in message
oups.com...
Cindy M.
wrote:
Hi Graham,

Is there any way to embed the SQL Server connection information
right
into a Word document?

Which version of Word are we discussing? And do your systems have
an
ODBC
driver for SQL Server installed?

I think it can't be done for OLE DB, as this also requires an
external
*.odc file. ODBC can probably do it. And a macro that links the
data
source when the file opens could probably work.

Another possibility (and it's what MSFT had in mind when they
designed
the interface) would be to distribute the *.odc file for the
connection
to everyone's "My Data Source" folder.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17
2005)
http://www.word.mvps.org

Word 2003, and all Microsoft systems have the SQL ODBC driver
installed.

The distribution path you describe would require an installer, which
is
a heck of a lot of trouble to get a 25-character connection string
down
to the users' machines. Honestly, I think this is another of those
situations where Microsoft didn't have *anything* in mind.

g.









  #9  
Old February 6th, 2007, 08:36 PM posted to microsoft.public.word.mailmerge.fields
Todd K.
external usenet poster
 
Posts: 48
Default Mail Merge to SQL Server without using an external ODC

I set up a datasource just to the SQL Database and tried adjusting the code
as follows and it still says it can't find the source:

Private Sub Document_Open()

Me.MailMerge.OpenDataSource _
Name:="GOLD-10455 ProjectONESQL.odc", _
Connection:="Provider = SQLOLEDB.1;Integrated Security=SSPI;" & _
"Persist Security Info=False;Initial Catalog=ProjectOne.adp;Data
Source=QryVW_Amendment;", _
SQLStatement:="SELECT * FROM [QryVW_Amendment]", _
SubType:=wdMergeSubTypeOther

Me.MailMerge.Destination = wdSendToNewDocument
Me.MailMerge.Execute
Windows(Me).Close wdDoNotSaveChanges

End Sub

"Peter Jamieson" wrote:

The Word
documents were rebuilt as Merge documents "linked" to the SQL tables, and
that worked great from my computer but not from anyone else's.


If you did this using a .odc, then you would have to distribute the .odc to
the other systems, and the other users would obviously have to have the
necessary permissions for the tables/views they need to access. You would
probably also have to re-issue the OpenDataSource call, for exampel in an
AutoOpen macro.

If you're using SQl Server with Windows Integrated Security, you shouldn't
have too many problems in this area. If you're not, then
a. everything gets a lot more difficult, straight away
b. I'm not even sure you will be able to make it work at all if you are
using SQL Server 2005 and the new drivers/providers that come with it. I
haven't been able to do it with SQl Server security so far.

Also, you may need to consider

http://support.microsoft.com/kb/825765

However, when you use a .odc you currently have two choices:
a. have a .odc for each table or view you want to connect to, and specify
any query information in the SQLStatement and SQLStatement1 parameters in
Word's OpenDataSource method
b. use one completely empty .odc (i.e. an empty text file) and specify
everything you need in the OpenDataSource call.

It seems likely that distributing a set of solutions based on (b) is likely
to be easier than basing them on (a).

Let's suppose you head for (b). You still have to write that OpenDataSource
call and specify where that empty .odc is. I suppose there are two possible
solutions:
a. put an empty .odc in every user's My Data Sources folder, build the
complete pathname for that file for each user and use that
b. use a completely standard pathname, e.g. c:\myodcs\empty.odc , for
everyone. can't do much harm - it's just an empty file and all the necessary
security is handled elsewhere. I hope.

As for the OpenDataSource code, with an empty.odc you will probably need
something like

ActiveDocument.MailMerge.OpenDataSource _
Name:="c:\myodcs\empty.odc", _
Connection:="Provider=SQLOLEDB.1;Integrated Security=SSPI;" & _
"Persist Security Info=False;Initial Catalog=mydb;Data Source=myserver;"
_
SQLSatatement:="SELECT FROM ""mytable"", _
SubType:=wdMergeSubTypeOther

where "myserver" is the name of the server running your SQl Server database,
"mydb" is the name of the database you want to access and "mytable" is the
table or view from which you want to retrieve data.

You'll need a different Provider name for SQl Server 2005's native
provider...

See if that gets you any further.

Peter Jamieson

"Todd K." wrote in message
...
1) Word 2003
2) The whole thing will be moved to SQL Server. So much needed to be
upgraded and changed from the current Access DB that we decided to build a
SQL Server project from scratch. Right now it is on my CPU as a MySQL
project, but upon completion we will move it to a separate server. The
Word
documents were rebuilt as Merge documents "linked" to the SQL tables, and
that worked great from my computer but not from anyone else's. So I
figured
how to use the code below on the current Access database allowing everyone
to
utilize them from their computers. When I essentially just changed the
code
in the OpenDataSource, it can't seem to find the SQL table
3) I just want to connect to a SQL Server table, no stored procedures.

"Peter Jamieson" wrote:

Which version of Word?

At the moment I'd guess your code is using DDE to get the data (i.e.
Access
will open and get the data).

When you say that the source changed to SQl Server do you mean that the
underlying data moved to SQL Server (and that you still have linked
tables
in your .adp) or that the whole thing moved to SQL Server?

For starters, to connect directly to SQL Server you need either
a. a suitable ODBC DSN (either "machine" DSN or .dsn file) or
b. a suitable OLE DB .udl file or
c. a suitable OLE DB .odc file

I can go into the details if necessary but maybe that will take you a
step
further. As a rule, an OLE DB connection is advisable, and essential if
your
SQl Server database has Unicode fields in it (which it almost certainly
will
have if it was created from an Access project using the Upsizing wizard.

Connecting to SQL Server tables and views should be straightforward,
security issues permitting, but connecting to stored procedures/stored
functions is another matter.

Peter Jamieson

"Todd K." wrote in message
news Peter -

I have a similar situation. I have code that works when the source is
an
Access table (see below), but when the source changed to SQL Server it
quit
working. Is there a different protocol for SQL Server or is it
probably
in
the routing?:

Private Sub Document_Open()

Me.MailMerge.OpenDataSource _
Name:="I:\Applications\Databases\ProjectOne.adp", _
LinkToSource:=True, _
Connection:="TABLE TblAmendment_Ren", _
SQLStatement:="SELECT * FROM [TblAmendment_Ren]"
Me.MailMerge.Destination = wdSendToNewDocument
Me.MailMerge.Execute
Windows(Me).Close wdDoNotSaveChanges

End Sub

"Peter Jamieson" wrote:

Did you work out how to do the ODBC connection?

Honestly, I think this is another of those
situations where Microsoft didn't have *anything* in mind.

I certainly don't understand why they insist that you have an external
object of some kind and don't allow DSN-less and ODC-less connections,
unless of course they were
a. worried that the end result would be loads of .doc files with
embedded
plain text login/password info.
(but if you're using SQL Server integrated security that's wouldn't be
an
issue anyway)
or
b. worried that then people would be able to distibute their merge
qapplications reasonably easily :-)

Peter Jamieson

"Graham" wrote in message
oups.com...
Cindy M.
wrote:
Hi Graham,

Is there any way to embed the SQL Server connection information
right
into a Word document?

Which version of Word are we discussing? And do your systems have
an
ODBC
driver for SQL Server installed?

I think it can't be done for OLE DB, as this also requires an
external
*.odc file. ODBC can probably do it. And a macro that links the
data
source when the file opens could probably work.

Another possibility (and it's what MSFT had in mind when they
designed
the interface) would be to distribute the *.odc file for the
connection
to everyone's "My Data Source" folder.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17
2005)
http://www.word.mvps.org

Word 2003, and all Microsoft systems have the SQL ODBC driver
installed.

The distribution path you describe would require an installer, which
is
a heck of a lot of trouble to get a 25-character connection string
down
to the users' machines. Honestly, I think this is another of those
situations where Microsoft didn't have *anything* in mind.

g.










  #10  
Old February 6th, 2007, 09:26 PM posted to microsoft.public.word.mailmerge.fields
Peter Jamieson
external usenet poster
 
Posts: 4,550
Default Mail Merge to SQL Server without using an external ODC

When you're dealing with SQL Server,
a. there's a machine where the SQL Server instance is located. That machine
has a name, e.g. "myserver"
b. that server can have a number of databases or "catalogs", each of which
has a name, e.g. "ProjectOne". They aren't /file names/ like
"ProjectOne.adp". However, just because your Access project is called
ProjectOne.adp does not mean that whoever has set up the back-end SQL Server
database has called the database "ProjectOne" either.

What is the server name? What is the database name?

Peter Jamieson


"Todd K." wrote in message
...
I set up a datasource just to the SQL Database and tried adjusting the code
as follows and it still says it can't find the source:

Private Sub Document_Open()

Me.MailMerge.OpenDataSource _
Name:="GOLD-10455 ProjectONESQL.odc", _
Connection:="Provider = SQLOLEDB.1;Integrated Security=SSPI;" & _
"Persist Security Info=False;Initial Catalog=ProjectOne.adp;Data
Source=QryVW_Amendment;", _
SQLStatement:="SELECT * FROM [QryVW_Amendment]", _
SubType:=wdMergeSubTypeOther

Me.MailMerge.Destination = wdSendToNewDocument
Me.MailMerge.Execute
Windows(Me).Close wdDoNotSaveChanges

End Sub

"Peter Jamieson" wrote:

The Word
documents were rebuilt as Merge documents "linked" to the SQL tables,
and
that worked great from my computer but not from anyone else's.


If you did this using a .odc, then you would have to distribute the .odc
to
the other systems, and the other users would obviously have to have the
necessary permissions for the tables/views they need to access. You would
probably also have to re-issue the OpenDataSource call, for exampel in an
AutoOpen macro.

If you're using SQl Server with Windows Integrated Security, you
shouldn't
have too many problems in this area. If you're not, then
a. everything gets a lot more difficult, straight away
b. I'm not even sure you will be able to make it work at all if you are
using SQL Server 2005 and the new drivers/providers that come with it. I
haven't been able to do it with SQl Server security so far.

Also, you may need to consider

http://support.microsoft.com/kb/825765

However, when you use a .odc you currently have two choices:
a. have a .odc for each table or view you want to connect to, and
specify
any query information in the SQLStatement and SQLStatement1 parameters in
Word's OpenDataSource method
b. use one completely empty .odc (i.e. an empty text file) and specify
everything you need in the OpenDataSource call.

It seems likely that distributing a set of solutions based on (b) is
likely
to be easier than basing them on (a).

Let's suppose you head for (b). You still have to write that
OpenDataSource
call and specify where that empty .odc is. I suppose there are two
possible
solutions:
a. put an empty .odc in every user's My Data Sources folder, build the
complete pathname for that file for each user and use that
b. use a completely standard pathname, e.g. c:\myodcs\empty.odc , for
everyone. can't do much harm - it's just an empty file and all the
necessary
security is handled elsewhere. I hope.

As for the OpenDataSource code, with an empty.odc you will probably need
something like

ActiveDocument.MailMerge.OpenDataSource _
Name:="c:\myodcs\empty.odc", _
Connection:="Provider=SQLOLEDB.1;Integrated Security=SSPI;" & _
"Persist Security Info=False;Initial Catalog=mydb;Data
Source=myserver;"
_
SQLSatatement:="SELECT FROM ""mytable"", _
SubType:=wdMergeSubTypeOther

where "myserver" is the name of the server running your SQl Server
database,
"mydb" is the name of the database you want to access and "mytable" is
the
table or view from which you want to retrieve data.

You'll need a different Provider name for SQl Server 2005's native
provider...

See if that gets you any further.

Peter Jamieson

"Todd K." wrote in message
...
1) Word 2003
2) The whole thing will be moved to SQL Server. So much needed to be
upgraded and changed from the current Access DB that we decided to
build a
SQL Server project from scratch. Right now it is on my CPU as a MySQL
project, but upon completion we will move it to a separate server. The
Word
documents were rebuilt as Merge documents "linked" to the SQL tables,
and
that worked great from my computer but not from anyone else's. So I
figured
how to use the code below on the current Access database allowing
everyone
to
utilize them from their computers. When I essentially just changed the
code
in the OpenDataSource, it can't seem to find the SQL table
3) I just want to connect to a SQL Server table, no stored procedures.

"Peter Jamieson" wrote:

Which version of Word?

At the moment I'd guess your code is using DDE to get the data (i.e.
Access
will open and get the data).

When you say that the source changed to SQl Server do you mean that
the
underlying data moved to SQL Server (and that you still have linked
tables
in your .adp) or that the whole thing moved to SQL Server?

For starters, to connect directly to SQL Server you need either
a. a suitable ODBC DSN (either "machine" DSN or .dsn file) or
b. a suitable OLE DB .udl file or
c. a suitable OLE DB .odc file

I can go into the details if necessary but maybe that will take you a
step
further. As a rule, an OLE DB connection is advisable, and essential
if
your
SQl Server database has Unicode fields in it (which it almost
certainly
will
have if it was created from an Access project using the Upsizing
wizard.

Connecting to SQL Server tables and views should be straightforward,
security issues permitting, but connecting to stored procedures/stored
functions is another matter.

Peter Jamieson

"Todd K." wrote in message
news Peter -

I have a similar situation. I have code that works when the source
is
an
Access table (see below), but when the source changed to SQL Server
it
quit
working. Is there a different protocol for SQL Server or is it
probably
in
the routing?:

Private Sub Document_Open()

Me.MailMerge.OpenDataSource _
Name:="I:\Applications\Databases\ProjectOne.adp", _
LinkToSource:=True, _
Connection:="TABLE TblAmendment_Ren", _
SQLStatement:="SELECT * FROM [TblAmendment_Ren]"
Me.MailMerge.Destination = wdSendToNewDocument
Me.MailMerge.Execute
Windows(Me).Close wdDoNotSaveChanges

End Sub

"Peter Jamieson" wrote:

Did you work out how to do the ODBC connection?

Honestly, I think this is another of those
situations where Microsoft didn't have *anything* in mind.

I certainly don't understand why they insist that you have an
external
object of some kind and don't allow DSN-less and ODC-less
connections,
unless of course they were
a. worried that the end result would be loads of .doc files with
embedded
plain text login/password info.
(but if you're using SQL Server integrated security that's wouldn't
be
an
issue anyway)
or
b. worried that then people would be able to distibute their merge
qapplications reasonably easily :-)

Peter Jamieson

"Graham" wrote in message
oups.com...
Cindy M.
wrote:
Hi Graham,

Is there any way to embed the SQL Server connection
information
right
into a Word document?

Which version of Word are we discussing? And do your systems
have
an
ODBC
driver for SQL Server installed?

I think it can't be done for OLE DB, as this also requires an
external
*.odc file. ODBC can probably do it. And a macro that links the
data
source when the file opens could probably work.

Another possibility (and it's what MSFT had in mind when they
designed
the interface) would be to distribute the *.odc file for the
connection
to everyone's "My Data Source" folder.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17
2005)
http://www.word.mvps.org

Word 2003, and all Microsoft systems have the SQL ODBC driver
installed.

The distribution path you describe would require an installer,
which
is
a heck of a lot of trouble to get a 25-character connection
string
down
to the users' machines. Honestly, I think this is another of
those
situations where Microsoft didn't have *anything* in mind.

g.












 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 06:09 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.