Disable/Enable button based on listtbox selection

G

Guest

I have a form with a listbox and a set of command buttons.
The contents of the listbox are dynamic and are affected by command buttons
being pressed.
Some of the command buttons affect whether an item is selected or not.
I need to enable/disable a command button based on whether a selection
exists in the listbox. This enabling/disablinmg needs to happen when a
different command button is pressed. e.g.
When button A pressed, if listbox has a selection, enable button B else
disable button B
 
M

Marshall Barton

mscertified said:
I have a form with a listbox and a set of command buttons.
The contents of the listbox are dynamic and are affected by command buttons
being pressed.
Some of the command buttons affect whether an item is selected or not.
I need to enable/disable a command button based on whether a selection
exists in the listbox. This enabling/disablinmg needs to happen when a
different command button is pressed. e.g.
When button A pressed, if listbox has a selection, enable button B else
disable button B


I'm not very good with list boxes, but I think you only have
to test the list box's ListIndex, which will be -1 if
nothing is selected.

Me.cmdbutton.Enabled = (Me.listbox.ListIndex >= 0)
 

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