E Mail From Access 2013 (1 Viewer)

Tor_Fey

Registered User.
Local time
Today, 19:25
Joined
Feb 8, 2013
Messages
121
Good Morning All;

I have the following code on a button in my database; which works fine and I'm happy with.

--------------------------------------------------------------
On Error GoTo Hell

Dim NameSpace As Object
Dim EmailSend As MailItem
Dim EmailApp As Object
Dim strUser As String

strUser = "Enter E Mail Address"
Set EmailApp = CreateObject("Outlook.Application") 'using the outlook object
Set NameSpace = EmailApp.GetNamespace("MAPI")
Set EmailSend = EmailApp.CreateItem(0)

EmailSend.Subject = "Request"
EmailSend.Body = "Test E Mail "
'EmailSend.Attachments.Add ("source/path")
'EmailSend.ReadReceiptRequested = True 'receipt request

EmailSend.Recipients.Add (strUser) 'send to?
'EmailSend.Save 'you MUSt save emails with attachments
EmailSend.Display 'display the email

Heaven:
Set EmailSend = Nothing
Exit Sub

Hell:
MsgBox Err.Description, vbCritical, "Error #: " & Err.Number
Resume Heaven

End Sub
--------------------------------------------------------------

But... what I was hoping to do; was perhaps use the ‘me.field name’ code to reference 2 dates from my form; and send them in to the ‘EmailSend.Body =’ area of my e mail as a concatenated text string.
Is this possible? And if so; how would I write the code for this?

Your help as always is very much appricaiated.

Kind Regards
Tor Fey
 

Orthodox Dave

Home Developer
Local time
Today, 19:25
Joined
Apr 13, 2017
Messages
218
(I like the Heaven and Hell references!)

That shouldn't be a problem. You'll need to convert the dates to a string with formatting you choose, e.g. Format(me.date,"dd/mm/yy") will produce a string, e.g. "22/06/17".

So you create a string variable (e.g. strBody) and build it up.

StrBody = "Email concerning the date " & Format(me.date,"dd/mm/yy").

Then when you have the complete string ready you go:

EmailSend.Body = StrBody

IF you format StrBody in HTML format, you'd use
EmailSend.HTMLbody = StrBody

There's a good reference here: http://www.granite.ab.ca/access/email.htm
 

Tor_Fey

Registered User.
Local time
Today, 19:25
Joined
Feb 8, 2013
Messages
121
Orthodox Dave;

Perfect thanks, I have it working now with the following code:

------------------------------------------------------------------------
On Error GoTo Hell
Dim NameSpace As Object
Dim EmailSend As MailItem
Dim EmailApp As Object
Dim strUser As String
Dim strBody As String
strUser = "Enter E Mail Address"
strBody = "Please Review And Approve My doc For: " & Format(Me.emaildate1, "dd/mm/yyyy ") & Format(Me.emaildate2, "dd/mm/yyyy")
Set EmailApp = CreateObject("Outlook.Application") 'using the outlook object
Set NameSpace = EmailApp.GetNamespace("MAPI")
Set EmailSend = EmailApp.CreateItem(0)
EmailSend.Subject = "Doc Request"
EmailSend.Body = strBody
'EmailSend.Attachments.Add ("source/path")
'EmailSend.ReadReceiptRequested = True 'receipt request
EmailSend.Recipients.Add (strUser) 'send to?
'EmailSend.Save 'you MUSt save emails with attachments
EmailSend.Display 'display the email
Heaven:
Set EmailSend = Nothing
Exit Sub
Hell:
MsgBox Err.Description, vbCritical, "Error #: " & Err.Number
Resume Heaven
End Sub

------------------------------------------------------------------------

Thanks so much for helping me resolve this issue :cool:

Regards
Tor Fey


(I like the Heaven and Hell references!)

That shouldn't be a problem. You'll need to convert the dates to a string with formatting you choose, e.g. Format(me.date,"dd/mm/yy") will produce a string, e.g. "22/06/17".

So you create a string variable (e.g. strBody) and build it up.

StrBody = "Email concerning the date " & Format(me.date,"dd/mm/yy").

Then when you have the complete string ready you go:

EmailSend.Body = StrBody

IF you format StrBody in HTML format, you'd use
EmailSend.HTMLbody = StrBody

There's a good reference here: http://www.granite.ab.ca/access/email.htm
 

Users who are viewing this thread

Top Bottom