Last week I was working on a Microsoft Access database I've been building and was making some changes to a form that allows users to select one or many items from a list box in order to set criteria for a report. By default, I wanted everything in the list box to be selected upon opening the form. Unfortunately there didn't seem to be a built-in "select all by default" option, so I put a little bit of code into the Form_Open event.
It did the trick for me, so I thought I'd share it with you today in case you're looking for the same thing:
Dim i As Integer
For i = 0 To Forms!frmFormName!lstListBoxName.ListCount - 1
Forms!frmFormName!lstListBoxName.Selected(i) = True
Next i
For the sake of any VBA beginners out there, I'll just remind you that you're going to want to change "frmFormName" to the name of your form, and "lstListBoxName" to the name of your list box.
Read More
It did the trick for me, so I thought I'd share it with you today in case you're looking for the same thing:
Dim i As Integer
For i = 0 To Forms!frmFormName!lstListBoxName.ListCount - 1
Forms!frmFormName!lstListBoxName.Selected(i) = True
Next i
For the sake of any VBA beginners out there, I'll just remind you that you're going to want to change "frmFormName" to the name of your form, and "lstListBoxName" to the name of your list box.