Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Automatic E-mails from Access 2000

Status
Not open for further replies.

SBelyea

Technical User
May 29, 2008
46
US
Hey everyone -

It's been a while since I've been on the boards. I've spent quite a bit of time trying to set up my database in such a way that I can execute some VBA code to automatically send e-mails when inspections are overdue for BMP (stormwater management "Best Management Practices").

I've created a query called qrySendMail that pulls all the information I need out of my database, such as OwnersBusiness (which is sent in the body of the e-mail).

This is the code I am currently using. It creates the e-mail perfectly, but does not send it automatically. I'd really appreciate any help available to get this working.

Code:
Public Function SendEmailAdvice() As String

'Dim db As DAO.Database, rs As DAO.Recordset
Dim sSQL As String

   'Set environment
   Set db = CurrentDb
   DoCmd.SetWarnings False
   Dim Email As String
   
   Email = "sbelyea@town.ashland.va.us"
   
   'Open the controlling recordset
   Set rs = db.OpenRecordset("qry_sendemail")
   While Not rs.EOF
       
       'For each record (Booking) send an email
       DoCmd.SendObject acSendNoObject, , , [Email], , , "BMP Inspection Reminder", _
           "A BMP inspection is overdue for " & rs![OwnersBusiness] & _
           vbCrLf & vbCrLf & "This e-mail was automatically generated. Do not reply."
       
       'Update the Booking table so that emails are not duplicated
       'sSQL = "UPDATE Booking SET EmailSent=-1 WHERE BookingID=" & rs![BookingID]
       'db.Execute sSQL
       
       'Cycle on to the next record
       rs.MoveNext
   Wend
   rs.Close
   Set rs = Nothing
   'Control recordset now closed
   
   'Reset environment
   DoCmd.SetWarnings True

End Function

The code is not my own - I can't remember the source I copied it from, but I have made changes to make it pull the proper info from my database.

A second question:

VBA hangs every time I try to run the code at this line
Code:
'Dim db As DAO.Database, rs As DAO.Recordset
, so I have commented it out. Can someone please enlighten me on how to get this line functioning? I've checked my references and DAO 3.6 is checked.

Thanks everyone!
 
Whoops! I figured it out - thanks tek-tips for the incredible FAQ section! :)
 
Check out a third party application called Persits ASP email. I found its much easier to use this via VBA, then to use the bottled stuff from Access. Very easy to use...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top