If statement to export query if record count is not null

H

H0MELY

Greetings, thank you very much to all who are reading this. Basically I have
an automated email that goes out every Monday. Very simply it uses
sendobject to email a query. I would like to add some logic that basically
looks at the record count and if it isn't null...sends teh email as is...if
the record count is empty I would like to have it send an email that
basically says "The record set this week is empty."

Below is the module converted from the original macro. I was having trouble
modifying the module so any help would be greatly appreciated. Thanks in
advance for any ideas.

Option Compare Database

'------------------------------------------------------------
' macro2
'
'------------------------------------------------------------
Function macro2()
On Error GoTo macro2_Err

DoCmd.SendObject acQuery, "Override - Invoice comments",
"MicrosoftExcelBiff8(*.xls)", "(e-mail address removed)", "", "", Eval("(Date()-7) &
"" to "" & (Date()-1) & "" - Overrides granted in TEMS"""), "", False, ""
DoCmd.Quit acExit


macro2_Exit:
Exit Function

macro2_Err:
MsgBox Error$
Resume macro2_Exit

End Function
 
D

David C. Holley

DCount() will return 0 if there are no records selected.

The following IF statement will count the number of records in a table named
tblOrders that have an OrderDate of Today. If you're dealing with something
complex invovling multiple tables where a query is needed, the DCount() can
operate on a query as in the later example...

If DCount("Id", "tblOrders", "OrderDate = Date()") = 0

If DCount("Id", "qryOrdersByDateByRegion", "OrderDate = Date() and
RegionId='Florida'") = 0
 

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