Hi!
Does my code look correct for running Auto EMails from Access?
Select Case Me.Email_Output_Option
Case 1
Dim mess_body As String
Dim rst As DAO.Recordset
Dim appOutLook As Outlook.Application
Dim MailOutLook As Outlook.MailItem
Set appOutLook = CreateObject("Outlook.Application")
Set MailOutLook = appOutLook.CreateItem(olMailItem)
Set rst = Form_F_People_Mailings.RecordsetClone
rst.MoveFirst
Do While Not rst.EOF
If IsNull(rst!Email) Then
MsgBox "skipping " & _
Form_F_People_Mailings.LastName & _
" no email address."
GoTo skip_email
End If
mess_body = "Dear " & rst!Salutation & " " & _
rst!LastName & "," & _
vbCrLf & vbCrLf & Me.Mess_Text
Set appOutLook = CreateObject("Outlook.Application")
Set MailOutLook = appOutLook.CreateItem(olMailItem)
With MailOutLook
.To = rst!Email
.Subject = Me.Mess_Subject
.Body = mess_body
If Left(Me.Mail_Attachment_Path, 1) <> "<" Then
.Attachments.Add (Me.Mail_Attachment_Path)
'.DeleteAfterSubmit = True
.Send
End With
skip_email:
rst.MoveNext
Loop
rst.Close
Set rst = Nothing
Case 2
Does my code look correct for running Auto EMails from Access?
Select Case Me.Email_Output_Option
Case 1
Dim mess_body As String
Dim rst As DAO.Recordset
Dim appOutLook As Outlook.Application
Dim MailOutLook As Outlook.MailItem
Set appOutLook = CreateObject("Outlook.Application")
Set MailOutLook = appOutLook.CreateItem(olMailItem)
Set rst = Form_F_People_Mailings.RecordsetClone
rst.MoveFirst
Do While Not rst.EOF
If IsNull(rst!Email) Then
MsgBox "skipping " & _
Form_F_People_Mailings.LastName & _
" no email address."
GoTo skip_email
End If
mess_body = "Dear " & rst!Salutation & " " & _
rst!LastName & "," & _
vbCrLf & vbCrLf & Me.Mess_Text
Set appOutLook = CreateObject("Outlook.Application")
Set MailOutLook = appOutLook.CreateItem(olMailItem)
With MailOutLook
.To = rst!Email
.Subject = Me.Mess_Subject
.Body = mess_body
If Left(Me.Mail_Attachment_Path, 1) <> "<" Then
.Attachments.Add (Me.Mail_Attachment_Path)
'.DeleteAfterSubmit = True
.Send
End With
skip_email:
rst.MoveNext
Loop
rst.Close
Set rst = Nothing
Case 2