Connecting Tech Pros Worldwide Help | Site Map

How to grab multiple email addresses using listbox?

Newbie
 
Join Date: Aug 2007
Posts: 1
#1: Aug 23 '07
Hi all,

I created a listbox with employees' names and email addresses in it, and a button which grabs email address once it's clicked. Currently I can only pick up one address at a time, but I also want to be able to grab multiple addresses. My code is as follows:

Private Sub SendCommand_Click()

Dim strName As String
Dim strEmail As String


strName = Me.List45.Column(0)
strEmail = Me.List45.Column(1)

DoCmd.SendObject acSendNoObject, "None", acFormatHTML, strEmail

End Sub

This can only pick up one email address when I look up the listbox and click the button. Can anyone show me how to grab multiple addresses?

Thanks a bunch,

zg
JConsulting's Avatar
Expert
 
Join Date: Apr 2007
Location: Houston
Posts: 601
#2: Aug 24 '07

re: How to grab multiple email addresses using listbox?


Quote:

Originally Posted by dragonfly8563

Hi all,

I created a listbox with employees' names and email addresses in it, and a button which grabs email address once it's clicked. Currently I can only pick up one address at a time, but I also want to be able to grab multiple addresses. My code is as follows:

Private Sub SendCommand_Click()

Dim strName As String
Dim strEmail As String


strName = Me.List45.Column(0)
strEmail = Me.List45.Column(1)

DoCmd.SendObject acSendNoObject, "None", acFormatHTML, strEmail

End Sub

This can only pick up one email address when I look up the listbox and click the button. Can anyone show me how to grab multiple addresses?

Thanks a bunch,

zg


This bit should get you pointed in the right direction
Expand|Select|Wrap|Line Numbers
  1. For Each x In List0.ItemsSelected
  2. If strAddress = "" Then
  3.    strAddress = List0.ItemData(x)
  4. Else
  5.     strAddress = strAddress & "; " & List0.ItemData(x)
  6. End If
  7. Next x
  8. If Nz(strAddress, "") = "" Then
  9. MsgBox "You must select an e-mail recipient"
  10. Exit Sub
  11. End If
  12.  
Newbie
 
Join Date: Aug 2007
Posts: 31
#3: Aug 24 '07

re: How to grab multiple email addresses using listbox?


This can be easily done throuugh following code

Private Sub testmultiselect_Click()
Dim oItem As Variant
Dim sTemp As String
Dim iCount As Integer

iCount = 0

If Me!Nameslist.ItemsSelected.Count <> 0 Then
For Each oItem In Me!Nameslist.ItemsSelected
If iCount = 0 Then
sTemp = sTemp & Me!Nameslist.ItemData(oItem)
iCount = iCount + 1
Else
sTemp = sTemp & ";" & Me!Nameslist.ItemData(oItem)
iCount = iCount + 1
End If
Next oItem
Else
MsgBox "Nothing was selected from the list", vbInformation
Exit Sub 'Nothing was selected
End If

Me!mySelections.Value = sTemp
End Sub
Private Sub clrList_Click()
Call clearListBox
Me!mySelections.Value = Null
End Sub

However, you have to create following fields & commands button also as follows:
List Box
----------------------------------------------------
Name : NamesList
Row Source Type : Table/Query
Row Source : SELECT Email FROM Employees
Multi Select : Extended
Width : 3.5"
Height : 0.75"


Text Box
-----------------------
Name : mySelections
Width : 3.5"
Height : 0.25"

Command Button
----------------------------------
Name : testmultiselect
Caption : Display Selected Items
Width : 1.375"
Height : 0.3"

Command Button
----------------------
Name : ClrList
Caption : Clear List
Width : 1.375"
Height : 0.3"
MGrowneyARSI's Avatar
Member
 
Join Date: Aug 2007
Posts: 92
#4: Aug 24 '07

re: How to grab multiple email addresses using listbox?


to select multiple address I use a sub form in datasheet view with a bolean field where the bolean is true you use those addresses with that and the code left above you should be able to do what you want unless I completely misunderstood the ?
Reply