Halt Action if query results do not contain X or Y?

Franky G

Registered User.
Local time
Today, 21:20
Joined
Feb 6, 2001
Messages
62
Hi,

I have a button which launches a make table query, starts MS Word, which reads from the table and mail merge's some of the results.

The query will typically return a good number of records, but I only want to mail merge ones where the field 'LetType' equals 6M or 30M. Often, there are no records which meet this criteria, therefore I would like Access to check whether any of the records returned in the query have 'LetType' (field name) 6M or 30M, if not, then to display a message that 'No Data Found' and quit the process, otherwise continue with the make table and Launch Word. (It doesn't really matter whether the check is carried out before the table is made or after) Any suggestions on how to do this would be welcome.

I have successfully checked whether a query returns any results, (If Dcount>0 [query]Then run Macro Else…etc etc). I’m not sure how to check whether a particular field equal ‘X’ or ‘Y’.

Thanks for any guidance, I’m off to Google again…

FrankyG
 
If using an Access query drag down the LetType field to the grid and enter "6M" into the Criteria cell and "30M" into the "or:" cell right below it.

If you are using VBA code add the line "WHERE LetType = '6M' OR LetType = '30M'"

HTH,
Jeff
 
I like to keep things easy to understand, even if not always the "best" way to solve a problem so when I have to change it a year from now, I don't have to figure it all out again. That being said I would create a query that returns the count based on your criteria. Then use dlookup to return that count to you. You can use dcount with a criteria also if you want to go that route. It is basically like a WHERE without the WHERE word in it.
 

Users who are viewing this thread

Back
Top Bottom