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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

preselect records in multiselect listbox 2

Status
Not open for further replies.

stupiet

Programmer
Aug 21, 2001
176
0
0
US
To anyone who can help,

I have a multiselect listbox that lists all the names you can send an e-mail to. Some of these names need to be already highlighted when the form is opened to ensure they are included. What is the code I can use to accomplish this?

Thanks for the help.

Tan
 
If you highlight them, will there not be a danger of the user un-selecting the names? Why not exclude the required emails from the select list and inform the user that emails will be sent to such-and-such a required list in addition to emails selected?
 
I did think of doing it that way, but there will be times where the user would want to exclude some of the pre-selected people. Especially if they send it out a second time etc.
 
A few notes.


Code:
Private Sub Form_Current()
strList = "AAA,BBB,CCC"
For i = 0 To Me.lstMultiSimple.ListCount
    If InStr(strList, Me.lstMultiExtended.ItemData(i)) > 0 Then
        Me.lstMultiExtended.Selected(i) = True
    End If
Next
End Sub
 
I'd use this:
For i = 0 To Me.lstMultiSimple.ListCount [!]- 1[/!]
 
Thanks Remou and PHV! The selection works great.

However, I ran into another problem after I ran this. My listbox is set up with 3 columns. The bound column has the e-mail address, the 2nd column the name and the third column has their job title.

I wanted to make the pre-selection criteria be based on their job title. So in order to make this work I had to set the job title as the bound column. This in turn messed up my e-mail function as that went off of the original bound column of the e-mail addresses.

Is there a way to preselect the people without having to change the bound column?

This is the code I used to recognize the e-mail addresses:
For Each var In ListSend.ItemsSelected
strList = ListSend.ItemData(var)
Next var
 
For i = 0 To Me!ListSend.ListCount - 1
If InStr(strList, Me!ListSend.Column(2, i)) > 0 Then
Me!ListSend.Selected(i) = True
End If
Next

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks PH!

Works like a charm. Learnt something new thanks to you guys again...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top