How to change Sql Command

J

josua

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 :)
 
D

Doug Robbins - Word MVP

That message is actually a security warning. See the following web page:

"Opening This Will Run the Following SQL Command" Message When You Open a
Word Document - 825765 at:

http://support.microsoft.com?kbid=825765


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
P

Peter Jamieson

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
 

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