MailMerge OpenDataSource Method

K

kenjin

My managed code application invokes Word 2003 automation to provide mailmerge functionality

My mail merge main document contains many (say 100) fields references. Our code generates SQL SELECT statements at runtime to retrieve these field values. The string length of the generated SELECT statements can exceed 1000 characters

According to the Word Visual Basic reference, the OpenDataSource method of the MailMerge object: "... If the query string is longer than 255 characters, SQLStatement specifies the first portion of the string, and SQLStatement1 specifies the second portion." At runtime my code generates an exception that reports the string length exceeds 255 when both SQLStatement (Len = 255) and SQLStatement1 (Len > 255) are provided

My questions are

1) Is the maximum SQLStatement string length that can be passed to this method 510 characters

2) Is there a another way to dynamically establish an ODBC datasource with a long query for MailMerge? (Referencing an MSQuery works well, but my queries must be generated at runtime

Thanks for your help

Ken
 
W

Wei-Dong XU [MSFT]

Hi Ken,

1. If your query is too long (more than 255 characters), please split it into tow parts and then set them to SQLStatement & SQLStatement1.

2. So far as I know, ODBC connection should be configured before the execution of the code.

If the issue remains or you have any question, please mail your project or create one demo project to me. I will research this more for you. If your
data source is from ACCESS or SQL server, we can use Northwind to perform the test. My email address is: (e-mail address removed)(please
remove online which is used to avoid the spam)

Expect to your reply!

Best Regards,
Wei-Dong Xu
Microsoft Product Support Services
Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
K

Kenjin

Hi XU

The question is

What is the maximum SQLStatement (+ SQLStatement1) string length that can be passed to the MailMerge OpenDatSource method

Ke
 
W

Wei-Dong XU [MSFT]

Hi Ken,

The maximum SQL string length is 511. This is the result length of the combined SQLStatement plus SQLStatement1. If you have any further question
, don't hesitate to let me know.

Best Regards,
Wei-Dong Xu
Microsoft Product Support Services
Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
G

Guest

Thanks Xu.

Did you arrive at 511 by experiment, by reference to the
VBA help topic on the OpenDataSource method, or is there
another source of documentation on this method?

Btw, my experiments yielded 510 as the answer.

Best Regards,

Ken
-----Original Message-----
Hi Ken,

The maximum SQL string length is 511. This is the result
length of the combined SQLStatement plus SQLStatement1. If
you have any further question
 
W

Wei-Dong XU [MSFT]

Hi Ken,

As I know, this is one value by design. Could you be so kind to paste your test code on the length here? Thanks!

Kindly Regards,
Wei-Dong Xu
Microsoft Product Support Services
Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top