1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
|
---------------------------
SELECT [Project Number] & ";" & [Project acronym] AS ProjectRef, a.Email, b.Message
FROM tblDeliverables AS a, tblMessage AS b
WHERE (((a.Email) Is Not Null) AND ((b.MessageID)=1) AND ((a.[Deliverable Status])="Pending"));
------------------------
Public Function SendEMail()
On Error GoTo Err_SendEmail
Dim objOutlook As New Outlook.Application
Dim objMail As Outlook.MailItem
Dim sSQL As String, db As DAO.Database, rs As DAO.Recordset
Dim sTitle As String, sFile As String, sErr As String
Dim sMessage As String
'Prelims
DoCmd.SetWarnings False
DoCmd.Hourglass True
Set db = CurrentDb
'Prepare email message
Set objMail = objOutlook.CreateItem(olMailItem)
With objMail
'Build recordset on recipients
sSQL = "SELECT Email as [Recipient], Message As [BodyText] FROM qryEmailList;"
Set rs = db.OpenRecordset(sSQL)
sMessage = rs![BodyText]
While Not rs.EOF
'Add Recipient
With .Recipients.Add(rs![Recipient])
.Type = olBCC
End With
rs.MoveNext
Wend
rs.Close
Set rs = Nothing
'Add the subject
.subject = "Delay in reporting Deliverables"
'Add standard message text to body
.Body = sMessage
'Send the mail message
.Send
End With
Set objMail = Nothing
Set objOutlook = Nothing
Exit_SendEmail:
DoCmd.SetWarnings True
DoCmd.Hourglass False
Exit Function
Err_SendEmail:
sErr = "Error " & Error & " / " & Err
MsgBox sErr, vbInformation + vbOKOnly, "Error on Email function"
Resume Exit_SendEmail
End Function |
Partager