[Access 2k3] Macro for sending mail if data ?

Jean-Didier

New member
Local time
Today, 05:22
Joined
Mar 26, 2010
Messages
8
Hello

I need you help please.


i have made an unmatched query and in my macro, i would like the database send me an email with an excel file, ONLY if there are some data in the query.
If the query is empty, no email

i've found this code but i dont know where i can put this code.. in a module, in a macro ?


Code:
Dim db As DAO.Database  
Dim rs As DAO.Recordset 
  
   Set db = CurrentDb 
   Set rs = db.OpenRecordSet("QueryName") 
  
   rs.MoveLast 
   rs.MoveFirst 
  
   If rs.RecordCount = 0 Then 
      Exit Sub 
   Else 
      ' Put your sendobject code here 
   End If

I'm a beginner in access, thank you for your help

Jean-Didier (and sorry for my very bad english ...)
 
Hello

It's OK.. But do you know if it's possible to use multiple crieria for this Dcount ?

Something Like This :
Code:
And(Dcount("*","Tab_ST_PDE")<1),Dcount("*","Qry_Incoherence")=0)

Only if this 2 conditions are True, the macro can run
I've try this code but it's not working....
 
No point checking if DCount() is less than 1. See what the help files explains.

The structure is:

If DCount(...) <> 0 AND DCount()<> 0 then

That's how both would look.
 

Users who are viewing this thread

Back
Top Bottom