disable text box if combo box is not filled

W

WJ

Please help me with this:

I have a combo box "Client_Broker_Combo", and a text box
following it "Broker_Other_Fill_In". So if the user
selects "Other" from the combo box, then I want to enable
the text box, so that the user can enter the broker name.

But right now, if the user does not choose anything from
the combo box, the text box is still enabled. And I want
to disable the text box if the user chooses nothing from
the combo. I've tried "isEmpty", "isNull", but nothing
works. so please help...The following is the code I have:



Private Sub Client_Broker_Combo_AfterUpdate()

If Client_Broker_Combo <> "Other" Then

Client_Broker_Other_Label.ForeColor = 8421504
Broker_Other_Fill_In.ForeColor = 8421504 'LAB
Broker_Other_Fill_In.Value = " " 'LAB
Broker_Other_Fill_In.Enabled = False


Else

Client_Broker_Other_Label.ForeColor = QBColor(0)
Broker_Other_Fill_In.ForeColor = QBColor(0)
Broker_Other_Fill_In.Enabled = True 'LAB


End If


End Sub
 
G

Guest

hi,
try seting the combo box default setting to enabled =
false in the combo box's property sheet.
when the form is open the combo box is empty and the text
box with by unenabled by default. if the use selects
something from the combo box, it will be enabled
programaticly.
 
W

WJ

Thanks for your reply!

But sorry I don't fully understand you. You mean to set
the "text box" to be disenabled, correct?

It works if I set the text box to be disabled. But
everytime I click on somewhere else, for example other
checkboxes, the text box would automatically enable itself
even if there was STILL nothing in the combo box above it.

So potentially, a user can put nothing in the combo, and
click somewhere else, and then enter something in the text
box.....

how can i solve this? maybe by writing some code?

thanks a lot.
 
G

Graham Mandeno

Hi WJ

The problem is that when the combo box is empty its value is Null. If you
compare Null with anything, then the result will be Null, which is NOT True.
Therefore the Else path of an If-Then-Else will always be taken.

The easiest way to fix this is to reverse the logic of your test:

If Client_Broker_Combo = "Other" Then
' enable the text box
Else
' disable the textbox
End If
 

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