Send email after inserting new record

Eeebs

Registered User.
Local time
Today, 06:32
Joined
Feb 10, 2009
Messages
14
Hi there.

I have a Table and a Form setup. What i want is an email sent to a specified email address after a new record is entered into the table (Via the Form). I would assume that the VBA code would be on "After_Insert()"...

Does anyone have any ideas? Thanks in advance:)
 
Look at SendObject in Help. Your assumption about the after insert event is correct.
 
Thanks for the pointer, works like a charm:)
However, just to eliminate the need for an attachment, is there a way to show the form contents in the message body of the email rather than an attachment file?
 
Despite its name, you do not have to include an attachment. The default object type is actually acSendNoObject. You can build a string to use in the body that includes data from the form. This type of thing:

strBody = "Dear " & Me.FirstName
 
Despite its name, you do not have to include an attachment. The default object type is actually acSendNoObject. You can build a string to use in the body that includes data from the form. This type of thing:

strBody = "Dear " & Me.FirstName

I see, I am new to the VBA side of access...can you explain how can i use that String so that it is sent as a email body? Do i replace the "acSendNoObject" with strBody = "Dear " & Me.FirstName"?

I would appreciate the help:)
 
No; look at help on SendObject. There are various arguments, in specific positions. The acSendNoObject is in the "what do I send?" argument. You want the body in the body argument. If you want it right in the SendObject line, you would eliminate the first part and just have:

"Dear " & Me.FirstName

The more complicated the body, the more likely I would build a string variable and then use that variable in the SendObject line, like:

Code:
  Dim strBody       As String

  strBody = "Dear " & Me.FirstName & "," & vbCrLf & vbCrLf
  strBody = strBody & "More text here..."

  DoCmd.SendObject acSendNoObject, , , , , , , strBody

with the other arguments filled in of course
 

Users who are viewing this thread

Back
Top Bottom