gmaxey
01-29-2013, 03:05 PM
Not that it will make a whit of difference in most cases, I was asked if there was a way to avoid looping through all the list entries in a mulit-select listbox to reset or clear the box.
I couldn't find something as simple as "oLB.Clear or oLB.Reset" but I did find that if I change the type to single and use .ListIndex = -1 and then change the type back that the loop is avoided.
To clear a listbox, pass it to this function:
Function ClearLB(ByRef oLB As Msforms.ListBox) As Boolean
Dim lngType As Long
lngType = oLB.MultiSelect
oLB.MultiSelect = fmMultiSelectSingle
oLB.ListIndex = -1
oLB.MultiSelect = lngType
ClearLB = True
End Function
Anybody aware of or see any problems with this approach?
I couldn't find something as simple as "oLB.Clear or oLB.Reset" but I did find that if I change the type to single and use .ListIndex = -1 and then change the type back that the loop is avoided.
To clear a listbox, pass it to this function:
Function ClearLB(ByRef oLB As Msforms.ListBox) As Boolean
Dim lngType As Long
lngType = oLB.MultiSelect
oLB.MultiSelect = fmMultiSelectSingle
oLB.ListIndex = -1
oLB.MultiSelect = lngType
ClearLB = True
End Function
Anybody aware of or see any problems with this approach?