i have it close to working, but i've run into one problem. i have code in
the onclick and beforeupdate events to load the info into textboxes on the
same form. the problem is that i want to limit the listbox to 8 choices max,
and when the 9th is selected, a message box pops up to indicate that 8 is the
limit. the problem is, even though i'm trying to cancel at the beforeupdate
event, it still selects the 9th item. here's my code:
Private Sub lboxOptions_Cli ck()
Dim frm As Form
Dim ctl As Control
Dim i As Long
Dim varItm As Variant
Dim strOptionCode As String
Dim currCount As Long
If booOpened Then
i = 0
numSelected = 0
booOpened = False
End If
Set frm = Forms!formNewVe hicleFinder
Set ctl = frm!lboxOptions
If ctl.ItemsSelect ed.Count numSelected Then
For Each varItm In ctl.ItemsSelect ed
currCount = ctl.ItemsSelect ed.Count
strOptionCode = DLookup("[optioncode]", "tblNewOptions" , "[option]
= " & Chr(34) & ctl.ItemData(va rItm) & Chr(34))
Me.Controls("tx tboxoption" & i).Value = strOptionCode
i = i + 1
Next varItm
numSelected = numSelected + 1
Else
numSelected = numSelected - 1
Me.Controls("tx tboxoption" & numSelected).Va lue = ""
End If
End Sub
Private Sub lboxOptions_Bef oreUpdate(Cance l As Integer)
If numSelected = 8 Then
Call MsgBox("Too many options were selected.", vbExclamation,
"Selection Error")
Cancel = -1
Me.lboxOptions. Undo
End If
End Sub
where booOpened is set to true in the form-open event and it, along with
numselected are set as public variables at the top of the code for the form.
what am i missing?
Scott McDaniel wrote:
>>hey... i have an unbound multiselect listbox on a form that i want to use to
populate text boxes on that form. so if a user selects the 3rd item in a
list of 20, how can i have that item show up in a text box? then, how can i
have a second selected item show up in a different text box, without
affecting the 1st one? (lboxOptions, txtboxOptions0, txtboxOptions1, etc..)
A multiselect listbox exposes an ItemsSelected collection which you can use, but it's not ordered by the user's choice.
I'm not sure how you'd determine the "first" choice vs the "second" choice, unless you store that information in
variables/arrays etc ... you could perhaps trigger this off the Click event of the listbox ...
See this link: http://msdn2.microsoft.com/en-us/lib...ffice.10).aspx
Scott McDaniel
scott@takemeou t_infotrakker.c om
www.infotrakker.com
--
Greg
Message posted via AccessMonster.c om
http://www.accessmonster.com/Uwe/For...ccess/200705/1