Send Email when new record is added

N

NewAccessDeveloper

I am a newbie and I need to know how to automatically send a email when a new
record has been added to a Access 2007 database...The more specific the
instructions the better; like the code and where you place it would be great
thanks for your help in advance.
 
A

Arvin Meyer [MVP]

You can use SendObject to email from a command button. Something like this
ought to work for you:

Private Sub cmdEmail_Click()
On Error GoTo Err_cmdEmail_Click

Dim strDocName As String
Dim strEmail As String
Dim strMailSubject As String
Dim strMsg As String

strDocName = Me.lstRpt
strEmail = Me.txtSelected & vbNullString
strMailSubject = Me.txtMailSubject & vbNullString
strMsg = Me.txtMsg & vbNullString & vbCrLf & vbCrLf & "Your Name" & _
vbCrLf & "MailTo:[email protected]"

DoCmd.SendObject objecttype:=acSendReport, _
ObjectName:=strDocName, outputformat:=acFormatTXT, _
To:=strEmail, Subject:=strMailSubject, MessageText:=strMsg

Exit_cmdEmail_Click:
Exit Sub

Err_cmdEmail_Click:
MsgBox Err.Description
Resume Exit_cmdEmail_Click

End Sub
 
N

NewAccessDeveloper

Thank for your response I so appreciate it! what if I wanted to get an
automatic email after updates or if someone added a record...how would the
code change? Wow, you are a MVP... I wish I could achieve that level one day
:)
 

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