Sending E-mail to different E-mail ID

  • Thread starter Thread starter James Hetfield
  • Start date Start date
J

James Hetfield

I have five (5) recods with differenct e-mail add.

Can I send single e-mail out of those records in a single
send?

Please advise because every time I send and e-mail using
DoCmd.SendObject, only the current record is being sent.

Thanks
 
Hi James,

Maybe something like this? Loop through values in a table (recordset) and
assign them to a string for dropping into the To argument of the SendObject
action.

Sub SendGroupEmail()
'If using Acc 97 change recordsets and
'connection to DAO equivalents.
On Error GoTo Err_SendGroupEmail
Const CancelSend = 2501
Dim cnYourConnection As ADODB.Connection
Dim rsYourRecordset As ADODB.Recordset
Dim strSQL As String
Dim intCtr As Integer
Dim i As Integer
Dim strTo As String

strSQL = "SELECT EmailAddress FROM tblEmailAddresses WHERE EmailAddress IS
NOT NULL"
Set cnYourConnection = CurrentProject.Connection
Set rsYourRecordset = New ADODB.Recordset

With rsYourRecordset
.Open strSQL, cnYourConnection, adOpenKeyset, adLockOptimistic
If Not .EOF Then
'Uusually movelast first to force
'accessing of all records but
'with only a small number we
'shouldn't need to
.MoveFirst
intCtr = .RecordCount
'Loop thru records and assign values to a string.
'Add a semi colon to separate the address until
'the last address is processed
For i = 0 To intCtr - 1
strTo = strTo & rsYourRecordset.Fields(0) & IIf(i <=
(intCtr - 2), ";", "")
.MoveNext
Next i
End If
End With
'Close what you opened
rsYourRecordset.Close
Set rsYourRecordset = Nothing
Set cnYourConnection = Nothing
'Send your email - Change/add optional arguments to suit
'The format argument is left out here so the user will be
'asked to nominate it when the email is generated. Add it in
'if you want a fixed format.
DoCmd.SendObject acSendTable, "tblEmailAddresses", , Trim(strTo), , , _
"YourSubject", "YourMessage", True

Exit_SendGroupEmail:
Exit Sub

Err_SendGroupEmail:
If CancelSend Then
Resume Next
Else
MsgBox Err.Number & ": " & Err.Description
End If
Resume Exit_SendGroupEmail

End Sub

HTH

Jamie
 
Hi Jamie!
Thanks for the reply.

It worked. But now my problem is I don't want the
message from Microsoft Outlook saying "A program is
trying to.
then you have to Choose from "YES" - "NO" - CANCEL"

Is there a way that the mail would be send without this
message appearing?
 
Back
Top