G
Guest
When a user clicks on one or more people in a multi-select list box, the
email addressees of these people are passed to an unbound text box,
txtSelected, as a string.
Then the user clicks on a command button called “Send Email†which opens up
Outlook and populates the To: box with the string of selected email addresses.
This works great, but …
I’ve since added a “Select All†command button on the form so the user can
quickly select all of the names in the listbox. The code selects all of the
names, but I don’t know how to edit it so all of the selected emails are
passed as a string to txtSelected (as would happen when the user manually
clicks on names in the ListBox).
Any ideas how I can edit the code for the “Select All†button to pass the
string of email addresses to txtSelected?
Thanks. Code below.
Kurt
“Select All†Command Button
-------------------------------------
Private Sub cmdAll_Click()
Dim lngX As Long
With Me.lstMailTo
For lngX = Abs(.ColumnHeads) To (.ListCount - 1)
.Selected(lngX) = True
Next
End With
End Sub
“Send Email†Command Button
---------------------------------------
Private Sub cmdEmail_Click()
Dim strEmail As String
strEmail = Me.txtSelected & vbNullString
DoCmd.SendObject To:=strEmail
End Sub
OnClick Code for List Box
---------------------------------
Private Sub lstMailTo_Click()
Dim varItem As Variant
Dim strList As String
With Me!lstMailTo
If .MultiSelect = 0 Then
Me!txtSelected = .Value
Else
For Each varItem In .ItemsSelected
strList = strList & .Column(0, varItem) & ";"
Next varItem
strList = Left$(strList, Len(strList) - 1)
Me!txtSelected = strList
End If
End With
End Sub
email addressees of these people are passed to an unbound text box,
txtSelected, as a string.
Then the user clicks on a command button called “Send Email†which opens up
Outlook and populates the To: box with the string of selected email addresses.
This works great, but …
I’ve since added a “Select All†command button on the form so the user can
quickly select all of the names in the listbox. The code selects all of the
names, but I don’t know how to edit it so all of the selected emails are
passed as a string to txtSelected (as would happen when the user manually
clicks on names in the ListBox).
Any ideas how I can edit the code for the “Select All†button to pass the
string of email addresses to txtSelected?
Thanks. Code below.
Kurt
“Select All†Command Button
-------------------------------------
Private Sub cmdAll_Click()
Dim lngX As Long
With Me.lstMailTo
For lngX = Abs(.ColumnHeads) To (.ListCount - 1)
.Selected(lngX) = True
Next
End With
End Sub
“Send Email†Command Button
---------------------------------------
Private Sub cmdEmail_Click()
Dim strEmail As String
strEmail = Me.txtSelected & vbNullString
DoCmd.SendObject To:=strEmail
End Sub
OnClick Code for List Box
---------------------------------
Private Sub lstMailTo_Click()
Dim varItem As Variant
Dim strList As String
With Me!lstMailTo
If .MultiSelect = 0 Then
Me!txtSelected = .Value
Else
For Each varItem In .ItemsSelected
strList = strList & .Column(0, varItem) & ";"
Next varItem
strList = Left$(strList, Len(strList) - 1)
Me!txtSelected = strList
End If
End With
End Sub