Enable command button when item selected from listbox (AC2007)

AOB

Registered User.
Local time
Today, 18:02
Joined
Sep 26, 2012
Messages
623
Hi guys,

This is a fairly basic problem so I'm disappointed with myself that I haven't been able to figure it out with a simple search!

I have a simple listbox (single column, no multi-selection)

I want to enable a command button when the user selects an item in the listbox / disable it if no items are selected.

I'm using the AfterUpdate event of the listbox, as follows :

Code:
Private Sub lstOptions_AfterUpdate()
 
    Select Case Me.lstOptions.ItemsSelected.Count
 
        Case 0
 
            Me.comConfirm.Enabled = False
 
        Case Else
 
            Me.comConfirm.Enabled = True
 
    End Select
 
End Sub

But when I select an item from the listbox, and debug the code, the Count is always zero? Even though I can see the item selected??

What am I doing wrong?

(Like I say, extremely disappointed with myself here, this is basic stuff! :banghead:)

Thanks

Al
 
Could it be something like.
Code:
Private Sub lstOptions_AfterUpdate()
    Me.comConfirm.Enabled = (Me.lstOptions.ListIndex <> -1) 
End Sub
 
Yeah that works... :rolleyes:

Thanks Paul (why doesn't my original effort work?)
 

Users who are viewing this thread

Back
Top Bottom