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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

When a record is added, I want to send email

Status
Not open for further replies.

jaxflorida

Technical User
Apr 16, 2002
27
0
0
US
Hello,

I have a program that populates my access 2000 database. When a record is added to a table, I need a way to send an alert to the person responsible for that information. It is my intention to just leave access up and running on a separte machine. I am sure this is possible, but I am new to VBA (or could it be done with a macro?). Either way, I appreciate any help you can give me.

Thanks
 
This code had been working for me for about 2 years and does exactly what you want I think

You need to have your version of the outlook library ticked as a reference

Found when you are in the VBA coding page open then click on tools>references

Dim objOutlook As New Outlook.Application
Dim objRem As MailItem

Set objRem = objOutlook.CreateItem(olMailItem)
objRem.To = "Email Address"
objRem.Subject = "Email Subject"
objRem.Body = "Information you want to send"
objRem.Send
 
I guess you enter data through a form...

Sub Form_AfterInsert()
dim strRecipient$
Dim strSubject$
Dim strBody$

On Error GoTo ErrHandler
'How do you get the recipient mail address?
strRecipient = "whoever@whatever.net"

strSubject = "This is the subject line"
strBody = "This is the message body"
DoCmd.SendObject , , , strRecipient, , , strSubject, strBody, True
'To send immediately, replace the trailing True with False
Finish:
Exit Sub

ErrHandler:
MsgBox Err.Number & ": " & Err.Description
Resume Finish
End Sub

No additional references needed.

Good luck
[pipe]
Daniel Vlas
Systems Consultant
danvlas@yahoo.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top