I have a list box that has 6 items, and I have coded the listbox to drop down. My question is, how do I get the selected item to be in the listbox after it's been selected. Here is the code I have in the lostfocus event:
'----------------------------------------------------------------
' Save selection for update query
'----------------------------------------------------------------
Dim frm As Form, ctl As Control
Dim varItm As Variant
Set frm = Forms!loginForm
Set ctl = frm!areaLB
For Each varItm In ctl.ItemsSelected
areaGbl = ctl.ItemData(varItm)
Next varItm
'----------------------------------------------------------------
' CHeck selection to load station dropdown
'----------------------------------------------------------------
If areaGbl = "Batting Cages" Then
Me.stationLB.RowSource = "cageTbl"
Else
Me.stationLB.RowSource = "RangeBays"
End If
Me.areaDsp = areaHld
Me.areaLB.Height = 500
What is rowsourcetype for areaLB list box control ?
If it's value list, just remove all items and add one record/value from areaGbl variable.
For nIndex = 0 To areaLB.ListCount - 1
areaLB.RemoveItem nIndex
Next nIndex
areaLB.AddItem areaGBL
If the rowsourcetype is table/query change the query of rowsource as follows
areaLB.rowsource = "Select <fieldName> from <table name> where
<fieldname> in '" & areaGBL & "'"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.