A Microsoft Office (Excel, Word) forum. OfficeFrustration

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 » OfficeFrustration forum » Microsoft Word » Mailmerge
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Problem querying SQL Server View as mail merge source



 
 
Thread Tools Display Modes
  #1  
Old September 7th, 2004, 10:37 PM
Todd H
external usenet poster
 
Posts: n/a
Default Problem querying SQL Server View as mail merge source

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=d eveloper;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

  #2  
Old September 8th, 2004, 09:26 PM
Debbie
external usenet poster
 
Posts: n/a
Default

Well, it depends on how the date is formatted in your
table. My format is usually __/__/__, so the criteria
will show up in the SQL statement as follows:

((yourdatefield)="1/1/04")

If it's as text and believe me I've seen it done, you
would need to make sure that how you type it is exactly
how it is in the database. In order to get a parameter
value window open to choose what dates you want I usually
just put [Date] or Between [StartDate] and [End Date] in
the criteria field.

If you are worried about how your date will look in your
merge fields once merged into Word, here's a tip.
{MERGEFIELD YOURDATEFIELD \@ "MMMM d, yyyy"}
How to add this formatting to your Word Doc, hit Alt + F9.


-----Original Message-----
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

.

 




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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Word-Excel 2003 - Mail Merge Recipients problem Gabbi Mailmerge 4 January 11th, 2005 04:11 AM
Word Mail Merge with SQL Data - URGENT !! Nitin Rana Mailmerge 1 August 21st, 2004 12:12 PM
Access and SQL AHopper General Discussion 26 August 3rd, 2004 07:01 PM
TRIGGER a VIEW with SQL for a LINKED SERVER (ACCESS DB) youssef General Discussion 10 July 13th, 2004 12:00 AM


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


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.