Applecore Pages on Microsoft Access

Clearing a Combo or List Box

If you are working with either a Combo Box or a List Box that doesn't support MultiSelect, then you can easily set the value of the control to nothing:

Private Sub cmdClearCombo_Click()
    Me!cboTable = ""
End Sub

If you are using a List Box that has its Multi Select property set to either simple or extended, you will need to loop through the ItemsSelected collection, and clear each item:

Private Sub cmdClearListBox_Click()
    Dim varItem As Variant
    For Each varItem in lstName.ItemsSelected
        lstName.Selected(varItem)=False
    Next varItem
End Sub

Conversely, if you wish to select all data in the List Box, then you will need to loop through the data, and set each item to selected:

Private Sub cmdSelectAll_Click()
    Dim lngSelection As Long
    For lngSelection = 0 To Me!lstData.ListCount - 1
        Me!lstData.Selected(lngSelection) = True
    Next lngSelection
End Sub

Top

 


HOME | NEW | TABLES | QUERIES | FORMS | REPORTS | GENERAL | API | DOWNLOADS | TUTORIAL | RESOURCES
E-MAIL
Copyright & Disclaimer

 

Last modified at 06/06/2006 14:54:06