PDA

View Full Version : Solved: enable or disable comboboxes based on textbox enter



ioncila
08-13-2012, 07:22 AM
Hi
First of all, this is a crosspost
http://www.ozgrid.com/forum/showthread.php?t=168597
And I am very sorry for that.
But I really need an urgent help in this and I didnt get any suggestions lately in that forum.

Here's my issue:
Hi
I'm have a form1 with several textboxes (textbox1, textbox2,...) and another form2 with comboboxes (combobox1, combobox2,...).
What I'm trying to do is:
Click in textbox1, open form2, enable combobox1, disable or lock other comboboxes
Click in textbox2, open form2, enable combobox2, disable or lock other comboboxes
and so on...

The code below works if I set it for just one combo in the change event. If I set for every combo, it locks all combos in form2

Private Sub ComboBox1_Change()
If Me.ComboBox1.ListIndex > -1 Then
Me.ComboBox2.Enabled = False
Me.ComboBox3.Enabled = False
End If
End Sub

How do I change code to work as I want?

Once again I apologize for this crosspost
Thank you very much in advance
Ioncila

CodeNinja
08-13-2012, 07:35 AM
Ioncila,
Not quite sure what you are trying to accomplish... from your write up, it seems like you have 2 userforms, one with text boxes and one with combo boxes. You want the user to click on a text box and show userform2 with locks on specific comboboxes within that userform. Is this correct? If so, why not use a command button instead of an on click event with a text box?
In your code, however, you show a combobox1 change event. This has nothing to do with another userform's text box event.

Please clarify.

Thanks,

CodeNinja

Bob Phillips
08-13-2012, 07:37 AM
Hi
First of all, this is a crosspost
http://www.ozgrid.com/forum/showthread.php?t=168597
And I am very sorry for that.
But I really need an urgent help in this and I didnt get any suggestions lately in that forum.

Learn from that mistake :)

Private Sub TextBox1_Enter()

With UserForm2

.ComboBox1.Enabled = True
.ComboBox2.Enabled = False
.ComboBox3.Enabled = False
'etc.

.Show
End With
End Sub

Private Sub TextBox2_Enter()

With UserForm2

.ComboBox1.Enabled = False
.ComboBox2.Enabled = True
.ComboBox3.Enabled = False
'etc.

.Show
End With
End Sub

'etc.

ioncila
08-13-2012, 08:15 AM
Learn from that mistake :)

Got the message :)

It's the perfect solution .
Thank you very much.
Ioncila

@codeninja: thanks for your reply too.