A Microsoft Word forum. Microsoft Office Word Forum - WordBanter

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 » Microsoft Office Word Forum - WordBanter forum » Microsoft Word Newsgroups » Mailmerge
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Using an .odc File to Mailmerge with SQL Server



 
 
Thread Tools Display Modes
  #1  
Old February 8th 05, 05:48 PM
Adam Froio
external usenet poster
 
Posts: n/a
Default Using an .odc File to Mailmerge with SQL Server

Hi,

I'm using an .odc file to pull data from SQL Server 2000 into a Word 2003
mailmerge.

My problem is getting the syntax correct so that I can dynamically create
sql statements to use for the merge.

For example, this works:
Word.MailMerge.OpenDataSource Name:="c:\mailmerge\CustomerData.odc",
SQLStatement:="SELECT * FROM [vwCustomerData]"

This, however, does not:
Word.MailMerge.OpenDataSource Name:="c:\mailmerge\vwCustomerData.odc",
SQLStatement:="SELECT * FROM [vwCustomerData] WHERE State = 'CT'"

I can't seem to find more than a couple examples on how to use an .odc in
this way and I can find none that use a sql statement any more complicated
than the first example above.

Any help or advice would be very much appreciated.

Thanks!
Adam


Ads
  #2  
Old February 8th 05, 10:57 PM
Peter Jamieson
external usenet poster
 
Posts: n/a
Default

I can't see anything obviously wrong with your SQL and similar statements
work OK here. However, you may need to surround CT with straight quotes
('CT') rather than the type of quote I think you have used in your message.
Other things I have noticed are
a. the .odc does not (as far as I can see) let you specify any SQL
explicitly. It just lets you specify a fully qualified table name. So you
have to specify any SQL in the OpenDataSource, or by setting
ActiveDocument.MailMerge.DataSource.QueryString
b. in fact, the .odc can be a completely blank file (which means you can
use a single .odc for all SQL Server queries) as long as you specify the
correct connection string in the COnnection parameter of the OpenDataSource
call. Once you have done one successful connection, you can generally get a
suitable connect string by looking at
ActiveDocument.MailMerge.DataSource.ConnectString (which will probably be
truncated to 255 characters, but you can usually get rid of some of quite a
lot of the parameters in the string)
c. the SQL interpreter used can be a bit touchy about the syntax and
sometimes fully qualifying the field names and or using table alias names
can make a difference, e.g. try

SELECT vwC.* FROM [vwCustomerData] vwC WHERE vwC.State = 'CT'

d. you will probably be limited to a 255-character query string.

Peter Jamieson
"Adam Froio" wrote in message
...
Hi,

I'm using an .odc file to pull data from SQL Server 2000 into a Word 2003
mailmerge.

My problem is getting the syntax correct so that I can dynamically create
sql statements to use for the merge.

For example, this works:
Word.MailMerge.OpenDataSource Name:="c:\mailmerge\CustomerData.odc",
SQLStatement:="SELECT * FROM [vwCustomerData]"

This, however, does not:
Word.MailMerge.OpenDataSource Name:="c:\mailmerge\vwCustomerData.odc",
SQLStatement:="SELECT * FROM [vwCustomerData] WHERE State = 'CT'"

I can't seem to find more than a couple examples on how to use an .odc in
this way and I can find none that use a sql statement any more complicated
than the first example above.

Any help or advice would be very much appreciated.

Thanks!
Adam




  #3  
Old February 9th 05, 07:56 PM
Adam Froio
external usenet poster
 
Posts: n/a
Default

Thanks Peter, I'll try your suggestions and post back on what I find.

Adam


"Peter Jamieson" wrote in message
...
I can't see anything obviously wrong with your SQL and similar statements
work OK here. However, you may need to surround CT with straight quotes
('CT') rather than the type of quote I think you have used in your message.
Other things I have noticed are
a. the .odc does not (as far as I can see) let you specify any SQL
explicitly. It just lets you specify a fully qualified table name. So you
have to specify any SQL in the OpenDataSource, or by setting
ActiveDocument.MailMerge.DataSource.QueryString
b. in fact, the .odc can be a completely blank file (which means you can
use a single .odc for all SQL Server queries) as long as you specify the
correct connection string in the COnnection parameter of the
OpenDataSource call. Once you have done one successful connection, you can
generally get a suitable connect string by looking at
ActiveDocument.MailMerge.DataSource.ConnectString (which will probably be
truncated to 255 characters, but you can usually get rid of some of quite
a lot of the parameters in the string)
c. the SQL interpreter used can be a bit touchy about the syntax and
sometimes fully qualifying the field names and or using table alias names
can make a difference, e.g. try

SELECT vwC.* FROM [vwCustomerData] vwC WHERE vwC.State = 'CT'

d. you will probably be limited to a 255-character query string.

Peter Jamieson
"Adam Froio" wrote in message
...
Hi,

I'm using an .odc file to pull data from SQL Server 2000 into a Word 2003
mailmerge.

My problem is getting the syntax correct so that I can dynamically create
sql statements to use for the merge.

For example, this works:
Word.MailMerge.OpenDataSource Name:="c:\mailmerge\CustomerData.odc",
SQLStatement:="SELECT * FROM [vwCustomerData]"

This, however, does not:
Word.MailMerge.OpenDataSource Name:="c:\mailmerge\vwCustomerData.odc",
SQLStatement:="SELECT * FROM [vwCustomerData] WHERE State = 'CT'"

I can't seem to find more than a couple examples on how to use an .odc in
this way and I can find none that use a sql statement any more
complicated than the first example above.

Any help or advice would be very much appreciated.

Thanks!
Adam






  #4  
Old February 10th 05, 07:06 PM
Adam Froio
external usenet poster
 
Posts: n/a
Default

Using the alias seem to do the trick -- thanks!

I used the following syntax:
SQLStatement:="SELECT * FROM [vwCustomerData] vwCD WHERE vwCD.State = 'CT'"

Thanks again!


"Adam Froio" wrote in message
...
Thanks Peter, I'll try your suggestions and post back on what I find.

Adam


"Peter Jamieson" wrote in message
...
I can't see anything obviously wrong with your SQL and similar statements
work OK here. However, you may need to surround CT with straight quotes
('CT') rather than the type of quote I think you have used in your
message. Other things I have noticed are
a. the .odc does not (as far as I can see) let you specify any SQL
explicitly. It just lets you specify a fully qualified table name. So you
have to specify any SQL in the OpenDataSource, or by setting
ActiveDocument.MailMerge.DataSource.QueryString
b. in fact, the .odc can be a completely blank file (which means you can
use a single .odc for all SQL Server queries) as long as you specify the
correct connection string in the COnnection parameter of the
OpenDataSource call. Once you have done one successful connection, you
can generally get a suitable connect string by looking at
ActiveDocument.MailMerge.DataSource.ConnectString (which will probably be
truncated to 255 characters, but you can usually get rid of some of quite
a lot of the parameters in the string)
c. the SQL interpreter used can be a bit touchy about the syntax and
sometimes fully qualifying the field names and or using table alias names
can make a difference, e.g. try

SELECT vwC.* FROM [vwCustomerData] vwC WHERE vwC.State = 'CT'

d. you will probably be limited to a 255-character query string.

Peter Jamieson
"Adam Froio" wrote in message
...
Hi,

I'm using an .odc file to pull data from SQL Server 2000 into a Word
2003 mailmerge.

My problem is getting the syntax correct so that I can dynamically
create sql statements to use for the merge.

For example, this works:
Word.MailMerge.OpenDataSource Name:="c:\mailmerge\CustomerData.odc",
SQLStatement:="SELECT * FROM [vwCustomerData]"

This, however, does not:
Word.MailMerge.OpenDataSource Name:="c:\mailmerge\vwCustomerData.odc",
SQLStatement:="SELECT * FROM [vwCustomerData] WHERE State = 'CT'"

I can't seem to find more than a couple examples on how to use an .odc
in this way and I can find none that use a sql statement any more
complicated than the first example above.

Any help or advice would be very much appreciated.

Thanks!
Adam








 




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 On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
mail merg file list auroracrum Mailmerge 3 March 11th 05 09:45 PM
mailmerge - excel datasource - other file extension? Ralf Pickel Mailmerge 1 February 14th 05 09:05 PM
mailmerge from excelfile with different file extension Ralf Pickel Mailmerge 0 January 31st 05 09:39 AM
MailMerge with Access File - need to format currency TheMomBon Mailmerge 1 January 26th 05 05:47 PM
Mailmerge Recipients doesn't work with SQL Server Gelatinous_Blob Mailmerge 2 December 17th 04 06:34 PM


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


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Copyright 2004-2014 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.