Private Sub Send_Email_Click()
'On Error GoTo Err_Send_Email_Click
Dim rec, a
Dim mysql$, num2proc%
Dim strMsg As String
Dim oLook As Object
Dim oMail As Object
Dim stDocName As String
Dim strEmail, strBCC 'strSubject, strMessage, strBCC
'strSubject = Forms!send_emails!Subject
'strMessage = Forms!send_emails!Email_Body
Set rec = Nothing
mysql$ = "SELECT * FROM Mail_Merge WHERE (([Do_Action])= " & True & ")"
Set rec = CurrentDb.OpenRecordset(mysql$, dbOpenDynaset)
If Not rec.BOF Then rec.MoveFirst
If rec.EOF And IsNull(rec.email) Then
Set rec = Nothing
MsgBox "No emails to send"
Exit Sub
End If
Do While Not rec.EOF
If Len(strBCC) > 0 Then
strBCC = strBCC & "; " & rec!email
Else
strBCC = rec!email
End If
rec.Edit
rec!Do_Action = False
'rec!Email_ID = Forms!send_emails!Email_ID
rec.Update
If Not rec.EOF Then
rec.MoveNext
Else
Exit Do
End If
Loop
Set rec = Nothing
strEmail = DLookup("[email]", "Users", "[Name] = " & "'" & [Forms]![Login]![AskName] & "'")
If IsNull(strEmail) Then
strEmail = "joseph.growney@accessreadysolution.com"
End If
If Len(Me.Attachment) > 0 Then
stDocName = Me.Attachment
a = Mid(stDocName, 1, 1)
If a = "#" Then stDocName = Mid(stDocName, 2, Len(stDocName) - 2)
Set oLook = CreateObject("Outlook.Application")
Set oMail = oLook.createitem(0)
With oMail
.to = strEmail
.body = Forms!send_emails!Send_Emailsub!Email_Body
.Subject = Forms!send_emails!Send_Emailsub!Subject
.attachments.Add stDocName
.bcc = strBCC
.display '.Send
End With
Set oMail = Nothing
Set oLook = Nothing
Else
Set oLook = CreateObject("Outlook.Application")
Set oMail = oLook.createitem(0)
With oMail
.to = strEmail
.body = Forms!send_emails!Send_Emailsub!Email_Body
.Subject = Forms!send_emails!Send_Emailsub!Subject
.bcc = strBCC
.display
'.Send
End With
Set oMail = Nothing
Set oLook = Nothing
End If
Exit_Send_Email_Click:
Exit Sub
Err_Send_Email_Click:
MsgBox Err.Description
Resume Exit_Send_Email_Click
End Sub
This is what I use It builds the Bcc based off of a subform in datasheet view and selects the users with bolean fields set to true then gets the body and subject from another form and sends the email here is the original code aswell the code above is slightly moded
'Use this to send Email from outlook with attachments
Dim strEmail As String
Dim strMsg As String
Dim oLook As Object
Dim oMail As Object
Set oLook = CreateObject("Outlook.Application")
Set oMail = oLook.createitem(0)
With oMail
.to = "someone@email.com"
.body = "Attached is a PDF file for your viewing"
.Subject = "Job Item"
.Attachments.Add ("C:\Documents and
Settings\ron_m\Desktop\rptJobItemStat.pdf")
'***** ".Display" is the command to preview instead of send *********
.Send
End With
Set oMail = Nothing
Set oLook = Nothing
End Function