Reply
 
Thread Tools Display Modes
  #1   Report Post  
Adam Froio
 
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


  #2   Report Post  
Peter Jamieson
 
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   Report Post  
Adam Froio
 
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   Report Post  
Adam Froio
 
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








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 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 04:09 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"