Following is basically the code I'm using.
Code:
Sub SendEmail(TotalDur As String, Optional AttachmentPath)
Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
Dim objOutlookAttach As Outlook.Attachment
Dim rstRRec As DAO.Recordset
Dim dbReporting As Database
Dim stLinkCriteria As String
Dim Ttest As String
Dim j As Single
Dim AttachmentArray(39) As Variant
Dim strTo As String
' Create the Outlook session.
Set objOutlook = CreateObject("Outlook.Application")
' Create the message.
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
' read from Email table to send email to correct people
Set dbReporting = CurrentDb()
Set rstRRec = dbReporting.OpenRecordset("tblEmailList", dbOpenDynaset)
'test
With objOutlookMsg
Do While Not rstRRec.EOF
If (1st Criteria is meet) Then
strTo = strTo & (rstRRec.Fields(0)) & ";"
Else
If (2nd Criteria is meet) then
strTo = strTo & (rstRRec.Fields(0)) & ";"
Else
If (3rd Criteria is meet) Then
strTo = strTo & (rstRRec.Fields(0)) & ";"
End If
End If
End If
rstRRec.MoveNext
Loop
strTo = Left(strTo, Len(strTo) - 1)
'****************************************
' Set the Subject, Body, and Importance of the message.
.To = strTo
.Subject = "Subject Information”
.Body = "Body Information”
.Importance = olImportanceHigh 'High importance
.Send
End With
Set objOutlookMsg = Nothing
Set objOutlook = Nothing
End Sub