Code: Select all
Private Sub Command11_Click()
'Sub SendEmail_Click()
Dim sql As String
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim adr As String
Dim objOL As Object
Dim objMsg As Object
' SQL to get unique email addresses
sql = "SELECT DISTINCT Email FROM qrySafetyTeam"
Set dbs = CurrentDb
' Open recordset
Set rst = dbs.OpenRecordset(Name:=sql)
' Loop through the records
Do While Not rst.EOF
'Concatenate email addresses
adr = adr & ";" & rst.Fields(0)
rst.MoveNext
Loop
' Close the recordset
rst.Close
' Remove the first ;
adr = Mid(adr, 2)
' Start Outlook
Set objOL = CreateObject(Class:="Outlook.Application")
' Create message
Set objMsg = objOL.CreateItem(0) ' 0 = olMailItem
' Set recipient to yourself
objMsg.To = "bozo@123456.net"
' Set BCC
objMsg.BCC = adr
' Set subject
objMsg.Subject = "Safety Team"
' Set message body
'objMsg.Body = ""
objMsg.HTMLBody = "<HTML><BODY><FONT FACE=Merriweather SIZE=14pt><P>This is an email to the Safety Team</P>" & _
"<P>This is <B>bold</B> and this is <I>italic</I></P></FONT></BODY></HTML>"
' Display the message
objMsg.Display
'set the font
End Sub