Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multiple entries from list box. 1

Status
Not open for further replies.
Apr 24, 2003
22
GB
Please, please, please can anyone help. I'm sure i have seen the answer to this question somewhere but i cannot find it.
I have a list box and I want to be able to select multiple entries from it and send these values to my e-mail. I know that i change the properties from Multi Select - None to Simple or extended but both of these have null values for the selection. To send the selection to my e-mail it needs to have a value which is the E-mail address.
I have the correct codeing for the send to e-mail I just need to find how to keep multiple values from the list selection.
Any help would be greatly appreciated.
Thankyou in advance
[smile]

 
I originally got this code from someone else on this forum (Sorry I can't remember who) but I use it all the time. It takes each item in your listbox and creates a string.

Dim ctlList As Control, varItem As Variant, strCollect As String

Set ctlList = Forms!YourForm!YourListBox
For Each varItem In ctlList.ItemsSelected

If strCollect = Empty Then
strCollect = ctlList.ItemData(varItem)
Else: strCollect = strCollect & "," & ctlList.ItemData(varItem)
End If

Next varItem

HTH,
Eric
 
This is how I do it.

In this case my list box control is named lstList and I am doing this in the forms module

Dim strListItems as String
Dim intListCt as Integer


For intListCt = 0 To Me.lstList.ListCount - 1
If Me.lstList.Selected(intListCt) = True And strListItems = "" Then
strListItems = Me.lstList.Column(0, intListCt)
ElseIf Me.lstList.Selected(intListCt) = True Then
strListItems = Me.lstList.Column(0, intListCt) & "; " & strListItems
End If
Next intListCt


This builds a string value that has all the selected items seperated by a semi-colon and is pulling the first column value of the list box record. You would have to modify it based on;
- How your email addressess have to be seperated for your email application
and
- Which column in you list box contains the email address.


Hope this helps.

OnTheFly
 
Hi That didn't work, to start with it gave me an error msg of Null value then it just didn't populate the .To box on Outlook with anything.
Below is the coding I am using. My list box is called List6 and the form is frmEmailposition.

************************************************************

Private Sub Command3_Click()
Dim List6 As String
Dim objOutlook As Outlook.Application
Dim objEmail As Outlook.MailItem

Dim strListItems As String
Dim intListCt As Integer


For intListCt = 0 To Me.List6.ListCount - 1
If Me.List6.Selected(intListCt) = True And strListItems = "" Then
strListItems = Me.List6.Column(0, intListCt)
ElseIf Me.List6.Selected(intListCt) = True Then
strListItems = Me.List6.Column(0, intListCt) & "; " & strListItems
End If
Next intListCt


List6 = Me.List6
Set objOutlook = CreateObject("Outlook.application")
Set objEmail = objOutlook.CreateItem(olMailItem)
With objEmail
.To = List6
.Display
End With
Exit Sub

End Sub

************************************************************

Thankyou so much for the help.
 
First, remove Dim List6 As String. You should not need this variable and it is very confusing since your list box is also named List6.

Then, delete the line
List6=Me.List6
as this doesn't seem to have any significant value here.

Then change
.To = List6

to

.To=strListItems

strListItems is the variable you stored your selected email addresses in so that is the variable you need to send to Outlook.

Hope this helps.

OnTheFly
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top