R
Raymond
I am trying to send one email with a attached report to people on a query
("Current_Case_Query_Within_15_Days"), the exact field in the query that
contains the email address is "UserID" but I continue to get an error on that
(UserID) field/part of the code. Can anyone help? I am new at this coding
part of access. See my code below.
Thanks in advance,
Raymond
Sub SendMessage()
Dim qdf As DAO.QueryDefs
Dim db As DAO.Database
Dim rsRecip As DAO.Recordset
Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
Dim objOutlookAttach As Outlook.Attachment
Dim clsSendObject As accSendObject
' Create the Outlook session.
Set objOutlook = CreateObject("Outlook.Application")
Set db = CurrentDb
' Create the message.
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
' Open the recordset so you can loop through it.
Set rsRecip = db.OpenRecordset("Current_Case_Query_Within_15_Days")
Do Until rsRecip.EOF
' Add recipient
' (your code)
Set objOutlookRecip = .Recipients.Add(rsRecip.UserID("EMail"))
objOutlookRecip.Type = olTo
rsRecip.MoveNext
Loop
With objOutlookMsg
' Add the To recipient(s) to the message.
' Set the Subject, Body, and Importance of the message.
.Subject = "This is an Automation test with Microsoft"
Outlook ""
.Body = "This is the body of the message." & vbCrLf & vbCrLf
.Importance = olImportanceHigh 'High importance
' Resolve each Recipient's name.
For Each objOutlookRecip In .Recipients
objOutlookRecip.Resolve
If Not objOutlookRecip.Resolve Then
objOutlookMsg.Display
End If
Next
.Send
End With
Set objOutlookMsg = Nothing
Set objOutlook = Nothing
End Sub
("Current_Case_Query_Within_15_Days"), the exact field in the query that
contains the email address is "UserID" but I continue to get an error on that
(UserID) field/part of the code. Can anyone help? I am new at this coding
part of access. See my code below.
Thanks in advance,
Raymond
Sub SendMessage()
Dim qdf As DAO.QueryDefs
Dim db As DAO.Database
Dim rsRecip As DAO.Recordset
Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
Dim objOutlookAttach As Outlook.Attachment
Dim clsSendObject As accSendObject
' Create the Outlook session.
Set objOutlook = CreateObject("Outlook.Application")
Set db = CurrentDb
' Create the message.
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
' Open the recordset so you can loop through it.
Set rsRecip = db.OpenRecordset("Current_Case_Query_Within_15_Days")
Do Until rsRecip.EOF
' Add recipient
' (your code)
Set objOutlookRecip = .Recipients.Add(rsRecip.UserID("EMail"))
objOutlookRecip.Type = olTo
rsRecip.MoveNext
Loop
With objOutlookMsg
' Add the To recipient(s) to the message.
' Set the Subject, Body, and Importance of the message.
.Subject = "This is an Automation test with Microsoft"
Outlook ""
.Body = "This is the body of the message." & vbCrLf & vbCrLf
.Importance = olImportanceHigh 'High importance
' Resolve each Recipient's name.
For Each objOutlookRecip In .Recipients
objOutlookRecip.Resolve
If Not objOutlookRecip.Resolve Then
objOutlookMsg.Display
End If
Next
.Send
End With
Set objOutlookMsg = Nothing
Set objOutlook = Nothing
End Sub