View Single Post
  #2   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Peter Jamieson Peter Jamieson is offline
external usenet poster
 
Posts: 4,582
Default Mail Merge with database and filtering

I believe this te problem described in an old article:

http://support.microsoft.com/kb/286880

so it does not look as if a fix will be available any time soon, if ever.

The only way I know how to deal with this reasonably easily from within
Word is to set up the query using VBA. If you open your mail merge main
document, then go into the VBA Editor (VBE), open the Immediate window
(e.g. use VBE Tools-View if you do not see it), then type

?activedocument.mailmerge.datasource.querystring

You should see the current query string. In your case, Word probably
tries to use something like

SELECT * FROM `Tablename` WHERE (`emailaddress` IS NULL OR
`emailaddress` = '') AND `payamt` = 1000

In other words, Word tries to deal with the two main possible ways you
could have a "blank" emailaddress.

Unfortunately, ODSO (see the article) screws this up and turns it into

SELECT * FROM `Tablename` WHERE (`emailaddress` IS NULL OR
`emailaddress` = '') OR (`emailaddress` IS NULL OR `emailaddress` = '')
AND `payamt` = 1000

which introduces the problem you see. As far as I can see, the only way
to fix this is to omit the test for NULL, using e.g.

SELECT * FROM `Tablename` WHERE `emailaddress` = '' AND `payamt` = 1000

/and/ to avoid going back into the Edit Recipients dialog box. If you go
into it, the problem will recur.

To set the querystring, you need to issue the following command in the
immediate window:

activedocument.mailmerge.datasource.querystring = "SELECT * FROM
`Tablename` WHERE `emailaddress` = '' AND `payamt` = 1000"

and press enter. Or you may find it useful to put small subroutines in
your normal.dotm file, e.g.

Sub getquery()
debug.print activedocument.mailmerge.datasource.querystring
end sub

Sub setquery()
activedocument.mailmerge.datasource.querystring = "whatever query you
want"
end sub

etc.

I do not think Microsoft has any excuse for not fixing this type of
error, as what they are currently doing is not "support"

Peter Jamieson

http://tips.pjmsn.me.uk

On 10/12/2009 17:37, osbornauto wrote:
Working with Office '07, I have a Word document (postcard) that pulls mail
merge info from an '07 Access database table. While in Word, under the
"Mailings" tab, I click on "edit recipient list" and want to select only
persons that have a blank email address and have spent over $1,000. I create
the filter as "emailaddress" is blank AND "payamt" is greater than or equal
to 1000. Then click OK. When I get back to the document, it should only
have 4 recipients, however there are 34. It has changed the query to email
is blank and payamt is over 1000 OR email is blank. So, the query has added
another layer with the "Or email is blank". I try to clear trhe query and
start over, but same results. Any ideas?