Select all button issues

  • Thread starter Thread starter gambit32
  • Start date Start date
G

gambit32

I have a button on my form that selects all clients in a list box. It
works in the sense that when I click it, it does select all clients.
The problem I'm running into is that when I first open the form the
button defaults to 'Unselect All Clients' when it should default to
'Select All Clients.' Those are the two states of the button. Ideally
I want to open the form and the button reads 'Select All Clients.'

My code:

Private Sub btnselectallcli_Click()
On Error GoTo Err_btnselectallcli_Click
Dim i As Integer

If btnselectallcli.Caption = "Select All Clients" Then
For i = 0 To listclient.ListCount - 1
listclient.Selected(i) = True
Next i
btnselectallcli.Caption = "Unselect All Clients"
Else
For i = 0 To listclient.ListCount - 1
listclient.Selected(i) = False
Next i
btnselectallcli.Caption = "Select All Clients"
End If


Exit_btnselectallcli_Click:
Exit Sub

Err_btnselectallcli_Click:
MsgBox Err.Description
Resume Exit_btnselectallcli_Click

End Sub


.....thanks for all the help the group has given me!

Mark
 
Call btnselectallcli_Click in your form's Load event (after first making
sure that the caption is what you want):

Private Sub Form_Load()
Me.btnselectallcli.Caption = "Select All Clients"
Call btnselectallcli_Click()
End Sub
 
Back
Top