Hi,
I am trying to make a form in access with few fields. I want the form records to be submitted to "MainTable" and also the values from the form fields to be mailed to 2 hardcoded email addresses. I also want to keep a track of the mails sent in another table "LogTable" with the content sent in the email.
Can someone help me as how to include form field values in the email and to keep a trail in another table.
A similar example code is as follows:
'******begin code******
Dim email, ref, origin, destination, notes As String
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
ref = Me!ref
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 = email
.Subject = ref & " " & origin & " " & destination
.Body = notes
.Send
End With
'**closes outlook
Set objEmail = Nothing
objOutlook.Quit
Exit Sub
'****end code****
I am trying to make a form in access with few fields. I want the form records to be submitted to "MainTable" and also the values from the form fields to be mailed to 2 hardcoded email addresses. I also want to keep a track of the mails sent in another table "LogTable" with the content sent in the email.
Can someone help me as how to include form field values in the email and to keep a trail in another table.
A similar example code is as follows:
'******begin code******
Dim email, ref, origin, destination, notes As String
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
ref = Me!ref
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 = email
.Subject = ref & " " & origin & " " & destination
.Body = notes
.Send
End With
'**closes outlook
Set objEmail = Nothing
objOutlook.Quit
Exit Sub
'****end code****