View Single Post
  #4   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Peter Jamieson Peter Jamieson is offline
external usenet poster
 
Posts: 4,582
Default How to change Sql Command

There are two main possible ways:

1. Use the Advanced Query Options to specify the criteria you want:
a. open your document, and accept the existing SQL command
b. Word 2007 ribbon-Mailings tab-Edit recipient list
c. Click the drop-down arrow in the heading of one of the columns of data
in the list, and select (Advanced...)
d. Enter your criteria in the boxes

2. Use Word VBA to open the data source, e.g.

Sub OpenMyDataSource()
ActiveDocument.MailMerge.OpendDataSource _
Name:="the full path name of your .xls", _
SQLStatement:="SELECT * FROM [student verification data$] WHERE ...your
criteria..."
End Sub

You may find that you cannot get (1) to work and that you have to use (2).
You should only need to execute this macro once (not each time you open the
document).

For some more info on how to do this, see
http://word.mvps.org/FAQs/Macros/VBA/CreateAMacro.htm

(However, in Word 2007 you will need to do things slightly differently,
starting from the Developer tab in the ribbon).

Peter Jamieson

"josua" wrote in message
...
Hi my name is josua,

I've problem.

When I open file M.word,

The popup window show

"
Opening this document will run the following SQL command:

SELECT * FROM 'student verification data$'

etc......
"

How to change this SQL commad, cause I want to add 'where' statement in
this
SQL command.

I use excel as database and I use Ms office 2007.

regards,

josua
nb: sorry if my english is bad