Email from list box

  • Thread starter dhoover via AccessMonster.com
  • Start date
D

dhoover via AccessMonster.com

I'm using the code below to email clients selected from a list box. However,
the code sends individual emails to each client, I'd like to generate one
email and send to all the selected clients.


Dim strTo As String
Dim varItem As Variant
Dim ctrl As Control

Set ctrl = Me.lstEmailAddresses

If ctrl.ItemsSelected.Count > 0 Then
For Each varItem In ctrl.ItemsSelected

strTo = ctrl.ItemData(varItem)

DoCmd.SendObject _
, _
, _
, _
, _
, _
("" & strTo), _
, _
, _
True

Next varItem


End If
 
D

Dirk Goldgar

dhoover via AccessMonster.com said:
I'm using the code below to email clients selected from a list box.
However,
the code sends individual emails to each client, I'd like to generate one
email and send to all the selected clients.


Dim strTo As String
Dim varItem As Variant
Dim ctrl As Control

Set ctrl = Me.lstEmailAddresses

If ctrl.ItemsSelected.Count > 0 Then
For Each varItem In ctrl.ItemsSelected

strTo = ctrl.ItemData(varItem)

DoCmd.SendObject _
, _
, _
, _
, _
, _
("" & strTo), _
, _
, _
True

Next varItem


End If


What you need to do is build a list of the selected e-mail addresses in a
string, and then pass that string to SendObject. Code would look something
like this:

strTo = vbNullString

With Me.lstEmailAddresses
For Each varItem In .ItemsSelected
strTo = strTo & ";" & .ItemData(varItem)
Next varItem
End With

If Len(strTo) > 0 Then
strTo = Mid(strTo, 2)
End If

DoCmd.SendObject _
Bcc:=strTo, _
EditMessage:=True
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top