Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Mailmerge and Fax / February 2005

Tip: Looking for answers? Try searching our database.

Using an .odc File to Mailmerge with SQL Server

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Adam Froio - 08 Feb 2005 16:48 GMT
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
Peter Jamieson - 08 Feb 2005 21:57 GMT
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
> Hi,
>
[quoted text clipped - 20 lines]
> Thanks!
> Adam
Adam Froio - 09 Feb 2005 18:56 GMT
Thanks Peter,  I'll try your suggestions and post back on what I find.

Adam

>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
[quoted text clipped - 45 lines]
>> Thanks!
>> Adam
Adam Froio - 10 Feb 2005 18:06 GMT
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!

> Thanks Peter,  I'll try your suggestions and post back on what I find.
>
[quoted text clipped - 49 lines]
>>> Thanks!
>>> Adam
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.