Thanks to Nathan and his faq702-2921 I was able to automate the sending of email messages from a command button cmdSendEmail on a subform called sfmMilestoneEntryEmail. I have now been asked to change this so that the email message is automatically sent based on the On Exit Event of a control called DateCompleted on the main form called frmMilestoneEntry. Can anyone tell me how to go about this. Writing code is a new adventure for me. Thanks in advance!!
Here is the code I have for the command button.
Private Sub cmdSendEmail_Click()
Dim email As String
Dim CCEmail As String
Dim ref As String
Dim notes As String
'**create variables for Outlook
Dim objOutlook As Outlook.Application
Dim objEmail As Outlook.MailItem
'**gathers information from subform and sets the string variable to the fields
email = Me.EmailNotice
CCEmail = Me.CCEmailNotice
ref = Me.EmailRef
notes = Me.EmailBody
'***creates an instance of Outlook
Set objOutlook = CreateObject("Outlook.application")
Set objEmail = objOutlook.CreateItem(olMailItem)
'***creates and sends email
With objEmail
.To = email
.CC = CCEmail
.Subject = ref
.Body = notes
.Send
End With
'**closes outlook
objOutlook.Quit
Set objEmail = Nothing
Exit Sub
End Sub
Here is the code I have for the command button.
Private Sub cmdSendEmail_Click()
Dim email As String
Dim CCEmail As String
Dim ref As String
Dim notes As String
'**create variables for Outlook
Dim objOutlook As Outlook.Application
Dim objEmail As Outlook.MailItem
'**gathers information from subform and sets the string variable to the fields
email = Me.EmailNotice
CCEmail = Me.CCEmailNotice
ref = Me.EmailRef
notes = Me.EmailBody
'***creates an instance of Outlook
Set objOutlook = CreateObject("Outlook.application")
Set objEmail = objOutlook.CreateItem(olMailItem)
'***creates and sends email
With objEmail
.To = email
.CC = CCEmail
.Subject = ref
.Body = notes
.Send
End With
'**closes outlook
objOutlook.Quit
Set objEmail = Nothing
Exit Sub
End Sub