WinXP & Access2K2
Using Arvin Myer’s email from access code.
I’ve been asked to provide a way to select all email addresses with a single
cmdButton, instead of clicking on each address in the list box. Is that
possible? Please don’t just answer yes. I need more help in what codingI
need to write.
Thanks.
you can just add the recipients to the Recipients collection...
Tweak his code a little...
Private Sub Command2_Click()
On Error GoTo ExitHere
Dim varItem As Variant
Dim objOutl As Outlook.Application
Dim objEml As Outlook.MailItem
Dim varMsg As Variant
Set objOutl = CreateObject("Outlook.application")
Set objEml = objOutl.createItem(olMailitem)
'loop through the selected items in your listbox...
For Each varItem In Me.lbxEMail.ItemsSelected
objEml.Recipients.Add Me.lbxEMail.ItemData(varItem)
Next varItem
varMsg = Me.txtMessage
'back to Arvin's code...
With objEml
'.To = strTo <---Already did that with the recipients
collection, so it's commented out.
.Subject = "SUBJECT LINE"
If Not IsNull(varMsg) Then
.Body = varMsg
End If
' Uncomment for attachment
' If Not IsMissing(varAttachment) Then
' .Attachments.Add varAttachment
' End If
'.Display
.Send
End With
Set objEml = Nothing
ExitHere:
Set objOutl = Nothing
'Set objEml = Nothing
End Sub
To test, comment out the
..SEND
and leave just the
..Display
so you can see what's going on. once everything's okay, change back
to just .Send.