Disable buttons based on listbox

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have listox1 and listbox2. What I want to do is when I click on listbox1
and some records will display in listbox2 but when there are no records
displayed in listbox2, i want to disable button1 and button2.

The code looks like this:

Private sub Listbox1_Click()

If Me.listbox2 = "" Then
Me.button1 = False
Me.button2.Enabled = False
Else
Me.button1.Enabled = True
Me.button2.Enabled = True
End If

However, it doesn't seem to work. Any ideas if i'm doing it correctly? Thanks.
ck
 
If Me.listbox2 = "" Then

Try

If Me.listbox2.ListCount = 0 Then

If you have column heads defined for the listbox, then this row is counted
also. If so, change the 0 to 1 in the above statement.

In your statement, since you haven't specified which property of the listbox
you are looking for, you get the default property which is the Value
property. The Value property will only be valid for a single select listbox
and will return the value of the selected row, if any, not the number of
rows.
 
Back
Top