I need to set up a double click event that will create a new email and
include certain fields from the record I'm currently in and use the
email address from another table/form (the 2 tables/forms are linked
by an ID#). I also want it to include a generic message in the body
of each email (like a signature). How do I do that?
Try something like:
Public Function EmailReps(strTo As String, Optional strSubject _
As String, Optional strMsg As String)
'Set reference to Outlook
On Error GoTo Errhandler
Dim objOutl As Outlook.Application
Dim objEml As Outlook.mailitem
Set objOutl = CreateObject("Outlook.application")
Set objEml = objOutl.createItem(olMailitem)
With objEml
.To = strTo
.Subject = strSubject
.Body = strMsg
.send
End With
ExitHere:
Set objOutl = Nothing
Exit Function
Errhandler:
MsgBox Err.Number & ": " & Err.Description
Resume ExitHere
End Function
Now call it like this:
Public Function MailIt()
Dim strSubject As String
Dim strMsg As String
Dim strTo As String
Select Case Me.txtSub
Case "AC"
strTo = "Ashley Cove;Change History"
Case "AR"
strTo = "Arbor Ridge;Change History"
Else
strTo = "Change History"
End Select
strSubject = "Contract Changes to [" & Me.txtSub & " - " & Me.txtLot &
" - " & Me.txtBuyer & "] By: " & Me.txtUser
strMsg = Me.txtContractID & ",," & """" & Format(Now, "mm/dd/yy h:nn
AM/PM") & """"
Call EmailReps(strTo, strSubject, strMsg)
Me.chkMailFlag = False
End Function
Notice how strSubject and strMsg are using form data in the subject and body
of the email.