Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trying to Run Auto Emails in outlook with Code

Status
Not open for further replies.

csunsun

Technical User
Apr 29, 2003
41
US
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
 
It seems ok, except for this bit:
Code:
    If Left(Me.Mail_Attachment_Path, 1) <> "<" Then
    .Attachments.Add (Me.Mail_Attachment_Path)
    '.DeleteAfterSubmit = True
    .Send
    End With

- End With is not needed
- End If is missing from before .Send
- You may wish to use .Display rather than .Send
 
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
If 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)
End If
'.DeleteAfterSubmit = True
.Send
'.Display by Remou
End With
Set MailOutLook = Nothing
skip_email:
rst.MoveNext
Loop
rst.Close
Set rst = Nothing
If Not MailOutLook Is Nothing Then Set MailOutLook = Nothing
appOutLook.Quit 'If you need it more, comment it out
Set appOutLook = Nothing
Case 2cond.
 
If I want to send the auto emails to all email addresses in a field in a table, and include a trackingID in the same table in addition to scripted text how do i add that to the code?

I want to send unique emails to unique records, grouped by ProviderID, RequestorEmail & DateProcessed

Included in the email:

From Table: TBL Daily Import
Email Recipient: RequestorEmail
Included in Message Body: Tracking ID

Thanks!!
 
Does this code look correct?

'Send Auto Response Emails to each Requestor
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 rst = TBL_Daily_Import.RequestorEmail.RecordsetClone
rst.MoveFirst
Do While Not rst.EOF
If rst!RequestorEmail & "" = "" Then
MsgBox "skipping " & _
TBL_Daily_Import.RequestorEmail & _
" no email address."
GoTo skip_email
End If
mess_body = "Dear Valued Client " & rst!RequestorEmail & " " & _
"," & _
vbCrLf & vbCrLf & Me.Mess_Text
Set MailOutLook = appOutLook.CreateItem(olMailItem)
With MailOutLook
.To = rst!RequestorEmail
.Subject = "Thank you for contacting Credit Requests Help Desk " & Me.TrackingID
.Body = "This automated note is to let you know we have received your email. Our goal is to process your credit request within the next three business days. Depending on processing time, you may not see credits on your very next invoice, but certainly the one after that. If you are asking a question about your returns, then please give us up to three business days to research your inquiry, and we will respond with the information you need." & _
"In order to serve you better, when you receive your invoice, you will also receive under separate cover, the detail of your submitted returns and which credits were granted and declined. Please refer to those emails for more details." & _
"Sincerely," & _
"Credit Requests Help Desk"


If Left(Me.Mail_Attachment_Path, 1) <> "<" Then
.Attachments.Add (Me.Mail_Attachment_Path)
End If
.DeleteAfterSubmit = True
.Send
End With
Set MailOutLook = Nothing
skip_email:
rst.MoveNext
Loop
rst.Close
Set rst = Nothing
If Not MailOutLook Is Nothing Then Set MailOutLook = Nothing
appOutLook.Quit
Set appOutLook = Nothing
Case 2cond.
 
csunsun

Does it run ok or it errors. If it errors in which line and what 's the error?
 
i get on error on the fist line..

Email_Output_Option

"Compile error: method or data member not found"


thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top