Sending email to all the addresses in a list box

  • Thread starter Thread starter Jo Gjessing
  • Start date Start date
J

Jo Gjessing

Hi all,

In a database of mine I've built a form with a listboks showing all the
email addresses registered in the database and a button which users shall
click to send email. As an user click the button the database shall open the
email form from Outlook with the addresses the user has marked filled in. As
the code behind the button I have:

DoCmd.SendObject acSendNoObject, stDocName, acFormatXLS, Me.email_recipient,
, , "Test Email", , True

The problem is that when I click the button I get an error message telling
that I use wrong data type. Is that because the addresses in the list box
come as an array? How can I rewrite the code som that it works? If you have
any idea I will be very glad to hear about it. Thank you very much in advance.

Jo
 
Try something more like

********
Dim varItem As Variant
Dim strEmailLst As String

'Build an e-mail listing from the selected listbox items
With Me.email_recipient
For Each varItem In .ItemsSelected
strEmailLst = strEmailLst & .Column(0, varItem) & ";"
Next varItem
End With

DoCmd.SendObject acSendNoObject, , acFormatXLS, strEmailLst, , , "Test
Email", , True
*********
--
Hope this helps,

Daniel Pineault
For Access Tips and Example: http://www.cardaconsultants.com/en/msaccess.php
If this post was helpful, please rate it by using the vote buttons.
 
Just reread your post and noticed that you weren't wanting to pull the
selected emails but rather all the emails from the list box. in this case
you'd need to change the 'email iteration slighhtly to the following


********
With Me.email_recipient
For i = 0 To .ListCount - 1
strEmailLst = strEmailLst & .ItemData(i) & ";"
Next i
End With

DoCmd.SendObject acSendNoObject, , acFormatXLS, strEmailLst, , , "Test
Email", , True
***********
--
Hope this helps,

Daniel Pineault
For Access Tips and Examples: http://www.cardaconsultants.com/en/msaccess.php
If this post was helpful, please rate it by using the vote buttons.
 
Back
Top