Select All in List Box

  • Thread starter Thread starter Bryan Hughes
  • Start date Start date
B

Bryan Hughes

Hello,

I am trying to create a command button that will select all Items in a list
box. How can I do this?

-Bryan
 
Dim vItem as variant

For Each vItem In Me.list0.ItemsSelected
Me.list0.Selected(vItem) = False
Next vItem

Make sure Multi select property for the list box is set to something other
than "None"

HTH,
Bob Slattery
 
Bob

I think you answered the reverse question (unselecting all
selected items), not what the O.P. asked.

HTH
Van T. Dinh
MVP (Access)
 
Something like (from one of my existing AXP databases):

Private Sub MSLBSelectAll(ctlListBox As Access.ListBox)
Dim intHeaderRow As Integer
Dim intIndex As Integer

On Error GoTo MSLBSelectAll_Err
Application.Echo False, "Processing ..."
intHeaderRow = Abs(CInt(ctlListBox.ColumnHeads))
For intIndex = 0 + intHeaderRow To ctlListBox.ListCount -
1
ctlListBox.Selected(intIndex) = True
Next intIndex

MSLBSelectAll_Exit:
Application.Echo True
Exit Sub

MSLBSelectAll_Err:
Select Case Err.Number
Case 0
Case Else
MsgBox "Error " & Err.Number & ": " &
Err.Description & vbCrLf & vbCrLf & _
"(Programmer's note:
Form_frmPrePivot_LL.MSLBSelectAll)" & vbCrLf, _
vbOKOnly + vbCritical, "Run-time Error!"
End Select
Resume MSLBSelectAll_Exit
End Sub

(beware of wrapping on the post).

HTH
Van T. Dinh
MVP (Access)
 
Back
Top