Select All in List Box

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
 
B

Bob Slattery

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
 
V

Van T. Dinh

Bob

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

HTH
Van T. Dinh
MVP (Access)
 
V

Van T. Dinh

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)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top