Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Enabling/Disabling a control from a ListBox

Status
Not open for further replies.

Pudsters

Technical User
Mar 16, 2006
151
US
I have a list box and a button, both disabled. I don't want them enabled until a selection has been made from another List box. How do I accomplish this?

I know how to do it from an Option button:

Private Sub optNo_Change()
If optNo = True Then

cmdButton1.Enabled = True
ListBox1.Enabled = True
Else
ListBox1.Enabled = False
ListBox1 = ""
cmdButton1.Enabled = False
End If
End Sub
 
Code:
If ListBox1.ItemsSelected.Count > 1 Then
  'Enable some stuff
Else
  'Disable said stuff
End If

Hoep this helps,
CMP

(GMT-07:00) Mountain Time (US & Canada)
 
It did not work. Here is my code: When I made a selection from a combo box I wanted two text boxes to become enabled.

Private Sub cbobox_Change()
If cboWarranty.ItemsSelected.Count > 1 Then

txtPolicyNum.Enabled = True
txtExpDate.Enabled = True
Else
txtPolicyNum.Enabled = False
txtExpDate.Enabled = False

End If
End Sub
 
Perhaps something like this ?
txtPolicyNum.Enabled = (cboWarranty.ListIndex >= 0)
or this ?
txtPolicyNum.Enabled = (Trim(cboWarranty.Value & "") <> "")

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
A ComboBox is a different beast then a ListBox and it looks PHV has you going the right direction.

CMP

(GMT-07:00) Mountain Time (US & Canada)
 
Thanks guys, I will play around with that, so far, I keep getting error messages.
 
It may help if you tell us what the error messages say.

Gerry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top