Sometimes you need to reset ComboBox and ListBox selections within Access forms. To do this you need to reset the ListIndex property to –1. However, the ListIndex property is read only, so another strategy is required. For a ComboBox the solution is simple, just set the Value property of the control to a null string. ListBox controls require a slightly different approach, depending on the MultiSelect setting.
I wrote the accompanying subroutine to demonstrate how reseting ListBox controls can be accomplished.
Dim
vnt As Variant'
Collection iterator
Dim
ctl As Access.Control
' Reset all combo and list boxes
With
TheForm
For
Each ctl In .Controls
If
TypeOf ctl Is ComboBox Then ctl.Value = ""
If
TypeOf ctl Is ListBox Then
With
ctl
Select
Case .MultiSelect
Case
0' None
.Value
= ""
Case
1' Simple
For
Each vnt In .ItemsSelected
.Selected(vnt)
= False
Next
Case
2 '
Extended
.Requery
End
Select
End
With
End
If' ListBox
Next
ctl
End
With
' TheForm