Just had to share this...
It works fine with err handling from null attachments and null CC's in case they want to email without a cc or attach, and im requiring the subj and body.
Make sure you have Outlook and DAO references checked.
It may seem odd to call variables then use the me.name, but it had probs use vars, maybe someone can point out why.
**********
Private Sub sendEmailBtn_Click()
On Error GoTo Err_sendEmail
Dim db As DAO.Database, rst As DAO.Recordset
Dim strBody, subject, email As String
Dim varCC, varAtt As Variant
Dim objOutlook As Object 'Outlook.Application
Dim objEmail As Object 'Outlook.MailItem
If IsNull(Me.emailSubj) Then
MsgBox "There must be something in the subject line for proper email functionality"
Exit Sub
End If
If IsNull(Me.emailBody) Then
MsgBox "There must be something in the body for proper email functionality"
Exit Sub
End If
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
Set db = CurrentDb
Set rst = db.OpenRecordset("tblHistory"
rst.AddNew
Set objOutlook = CreateObject("Outlook.application"
Set objEmail = objOutlook.CreateItem(olMailItem)
With objEmail
.to = email
.subject = subject
.Body = strBody
If IsNull(varCC) And IsNull(varAtt) Then
.Send
ElseIf IsNull(varAtt) Then
.CC = varCC
.Send
Else
.Attachments.Add varAtt, olByValue, 1
.Send
End If
End With
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.