Problem querying SQL Server View as mail merge source

T

Todd H

Hi,

I'm using the following code to perform a mail merge from an Access
project:

With docMailMergeSource.MailMerge
..MainDocumentType = wdFormLetters
..OpenDataSource Name:=<datasource path>, _
Format:=wdOpenFormatAuto, ReadOnly:=True, LinkToSource:=False, _
ConfirmConversions:=False, _

SQLStatement:="SELECT * FROM dbo.WelcomeLetterMailMerge_V WHERE
AgreementDate >= 'Sep 1, 2001'", _

Connection:="DRIVER=SQLServer;SERVER=SOMESVR;UID=developer;PWD=;APP=Microsoft
Data Access Components"

..Destination = wdSendToNewDocument
..Execute
..MainDocumentType = wdNotAMergeDocument
End With


The problem I'm having is with the SQLStatement. As is, I get a word
is unable to open datasource error. If I change it to "SELECT * FROM
dbo.WelcomeLetterMailMerge_V WHERE 1=1", everything works fine, but I
don't have any date constraint. Am I representing the date in an
incorrect format? If I paste the query into Query Analyzer, it runs
just fine. I've tried using # marks, and double quotes to surround
the date, but haven't had any luck.

Any Suggestions?

Thanks,

Todd
 

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