Send Email with form data in Access using Outlook (1 Viewer)

scgoodman

scgoodman
Local time
Today, 02:47
Joined
Jun 6, 2008
Messages
87
Trying to send a email through a command button. I get the email correctly, however I would like the form data in the subject line. Can you please help?
Here is the code I have so far...this works to pull up an email, but I need the form data. The table the form is built from is tbl_Master Data Table, and the form is frm_Master Data Table. The MAWB and HAWB is the fields from the form I need in the subject line.
Private Sub Command120_Click()
DoCmd.SetWarnings True
Dim Email As String
Dim MAWB As String
Dim HAWB As String
Dim notes As String
'**create variables for Outlook
'Dim objOutlook As Outlook.Application'
'Dim objEmail As Outlook.MailItem'
'**gathers information from your form. this sets the string variable to your fields
'Email = Me!Email
'MAWB = Me!MAWB
'HAWB = Me!HAWB
'origin = Me!origin
'destination = Me!destination
'notes = Me!notes
'***creates an instance of Outlook
Set objOutlook = CreateObject("Outlook.application")
Set objEmail = objOutlook.CreateItem(olMailItem)
'***creates and sends email
With objEmail
.To = strEmail
.Subject = MAWB & HAWB
.Body = notes
.Display
End With
End Sub
 

scgoodman

scgoodman
Local time
Today, 02:47
Joined
Jun 6, 2008
Messages
87
No, I am trying to send form information. Take several pieces from a form to input into an email.
 

GaryPanic

Smoke me a Kipper,Skipper
Local time
Yesterday, 23:47
Joined
Nov 8, 2005
Messages
3,296
try this

Private Sub Command21_Click()


Dim EmailApp, NameSpace, EmailSend As Object

Set EmailApp = CreateObject("Outlook.Application")
Set NameSpace = EmailApp.GetNamespace("MAPI")
Set EmailSend = EmailApp.CreateItem(0)

EmailSend.To = [Forms]![claimsreporter]![Text14]
EmailSend.Subject = "Claims Report for" & " " & [Forms]![claimsreporter]![Text3]
'EmailSend.Message = "h:\email.txt" (THIS FAILED)
EmailSend.Attachments.Add "C:\temp\liabilites.xls"
EmailSend.Display

Set EmailApp = Nothing
Set NameSpace = Nothing
Set EmailSend = Nothing

'Kill "C:\temp\test2.xls"
 

GaryPanic

Smoke me a Kipper,Skipper
Local time
Yesterday, 23:47
Joined
Nov 8, 2005
Messages
3,296
EmailSend.Subject = "Claims Report for" & " " & [Forms]![claimsreporter]![Text3] fields on form

'EmailSend.Message = "h:\email.txt" (THIS FAILED)
again can be tweak to fields on form (however you lose formatting )
 

siddharthnk

New member
Local time
Today, 12:17
Joined
Jul 23, 2013
Messages
3
Hi,

This post is pretty old and I hope that you are still active on this forum.
Your solution has worked nicely. It would be great if you could help me with the following aspects.
1) I need to format some text i.e. bold and color it
2) insert data from a query into the email. The query might contain about 8 fields and up to 10 records. Generally it has a single record.

Is this possible?

Your help will be greatly appreciated.

Thanks and Regards,
Sidd
 

Users who are viewing this thread

Top Bottom