Clearing List Boxes

  • Thread starter Thread starter Virgil Layne
  • Start date Start date
V

Virgil Layne

I'm trying to create a procedure to clear all selections
from a form's controls (text combo boxes and list boxes).
Combo boxes are no problem. I can use the Me.
[ControlName].SetFocus and me.[ControlName]="" lines to
set each combo box to blank. List boxes are a problem. I
can't find a thing to clear any selections. I've tried
ItemsSelected, ItemData among other listbox options.
 
Hi,

How about this for a command button to clear a list box?

Dim lngX As Long

With Me.lstMyListBox
For lngX = (.ItemsSelected.Count - 1) To 0 Step -1
.Selected(.ItemsSelected(lngX)) = False
Next lngX
' Return to first item in list box
.SetFocus
.ListIndex = Abs(.ColumnHeads)
End With

Hope that helps,
Jeff Conrad
Bend, Oregon
 
It does. Thanks for the quick response! BTW, I found
another solution almost immediately after I posted the
message. (D'Oh!!) Set each selection to false via a For
Each...Next loop:
For Each indexItem In Me.[ControlName].ItemsSelected
Me.[ControlName].Selected(indexItem ) = False
Next indexItem

Thanks again for your help!
-----Original Message-----
Hi,

How about this for a command button to clear a list box?

Dim lngX As Long

With Me.lstMyListBox
For lngX = (.ItemsSelected.Count - 1) To 0 Step -1
.Selected(.ItemsSelected(lngX)) = False
Next lngX
' Return to first item in list box
.SetFocus
.ListIndex = Abs(.ColumnHeads)
End With

Hope that helps,
Jeff Conrad
Bend, Oregon

I'm trying to create a procedure to clear all selections
from a form's controls (text combo boxes and list boxes).
Combo boxes are no problem. I can use the Me.
[ControlName].SetFocus and me.[ControlName]="" lines to
set each combo box to blank. List boxes are a problem. I
can't find a thing to clear any selections. I've tried
ItemsSelected, ItemData among other listbox options.


.
 
Glad you got it working and thanks for posting an alternative.

Jeff Conrad
Bend, Oregon

Virgil Layne said:
It does. Thanks for the quick response! BTW, I found
another solution almost immediately after I posted the
message. (D'Oh!!) Set each selection to false via a For
Each...Next loop:
For Each indexItem In Me.[ControlName].ItemsSelected
Me.[ControlName].Selected(indexItem ) = False
Next indexItem

Thanks again for your help!
-----Original Message-----
Hi,

How about this for a command button to clear a list box?

Dim lngX As Long

With Me.lstMyListBox
For lngX = (.ItemsSelected.Count - 1) To 0 Step -1
.Selected(.ItemsSelected(lngX)) = False
Next lngX
' Return to first item in list box
.SetFocus
.ListIndex = Abs(.ColumnHeads)
End With

Hope that helps,
Jeff Conrad
Bend, Oregon

I'm trying to create a procedure to clear all selections
from a form's controls (text combo boxes and list boxes).
Combo boxes are no problem. I can use the Me.
[ControlName].SetFocus and me.[ControlName]="" lines to
set each combo box to blank. List boxes are a problem. I
can't find a thing to clear any selections. I've tried
ItemsSelected, ItemData among other listbox options.


.
 
Back
Top