PDA

View Full Version : Combobox change



mqdias
11-06-2007, 03:33 AM
Hi,

I have the following problem:
In Combobox1 i have 2 items: "Air", "Water". When i click "Water", Userform2 is shown with other options. When i click a "OK" button it closes this userform and in combobox1, "water" stays choosen.
Later, if i decide to change options in that Userform2, i'm going to click again in Combobox1 to select "Water", so that Userform2 can be shown. The problem is that when i click this second time on "Water", the Userform2 isn't shown.

How can i make this Userform2 to be shown again with the second click in "Water"?

Thank you

figment
11-06-2007, 05:56 AM
you need to rewrite the code so that it resets the combobox after you make a selection.

mqdias
11-06-2007, 06:41 AM
Hi,

Thanks for the reply.
I'0ve already tried something like that. the problem is that if i insert that code, after i choose an item at first, the combobox doesn't fix my option and "resets" it.

Do you know how can i do to solve this?

figment
11-06-2007, 06:50 AM
your going to have to post the code, for me to be able to offer additional help. mostlikly the problem is where you have the code, or when your reseting the box. you should reset the box when you leave the second form.

mqdias
11-06-2007, 07:04 AM
Good!

The code is quite big in the "change" event...I understood what you said, but if i reset the combobox after closing Userform2, the combobox doesn't fix my option.
If you really need the code i'll post it.

Thank you once more,

figment
11-06-2007, 07:12 AM
sounds like your reseting the combo box, befor everything is done looking at it. the reset has to be the vary last thing that your code dose. again having the code would help.

rory
11-06-2007, 07:13 AM
Why not just add a 'Change Options' button?

figment
11-06-2007, 07:24 AM
come now Rory that is obviously to easy and option.

mqdias
11-06-2007, 07:25 AM
Hi rory,

that is a good idea, but i have no more space in my userform to display optionbuttons to all the items that i have in the combobox.

Thanks anyway

rory
11-06-2007, 07:29 AM
You would only have 1 button next to the combobox that allows you to bring up userform 2 and change the options. (I'm not talking about using optionbuttons instead of the combobox!)

mqdias
11-06-2007, 07:39 AM
I see...but in this case i need to impose to open the Userform2 at combobox1 changing. If i do not impose it, the user may not realize that must use Userform2 to specify some values.

the code is:

Private Sub ComboBox1_Change()
If ComboBox1.Value = "Ar" Then
TextBox1.Value = ""
End If
If ComboBox1.Value = "Vapor / ?gua" Then
TextBox1.Value = ""
If Folha1.Cells(16, 11) <> 1 Then UserForm4.Show
End If
If ComboBox1.Value = "Gases de escape" Then
TextBox1.Value = ""
If Folha1.Cells(16, 11) <> 1 Then UserForm7.Show
End If
If ComboBox1.Value = "Personalizar" Then
TextBox1.Enabled = True
CommandButton1.Enabled = True
Else
TextBox1.Enabled = False
CommandButton1.Enabled = False
End If
End Sub

rory
11-06-2007, 07:48 AM
You can do that using the Change code you already have. What I am suggesting is that you also have a button that loads the userform so that if a user wants to go back and change the options, they just click a 'Change Options' button rather than having to try and reselect the item in the combobox. You can also use the Change event to enable and disable the new button depending on the value chosen.

mqdias
11-06-2007, 07:58 AM
Good, it's a good alternative!

I wonder if you can help me on a code to automaticly run that new commandbutton, like if we click on it. This will make that, at the first time, the user it's oblied to insert options in that 2nd userform.

Thank you soo much!!!

figment
11-06-2007, 08:04 AM
somthing like this:

Private Sub ChangeButton_Click()
Call ComboBox1_Change
End Sub

Private Sub ComboBox1_Change()
If ComboBox1.Value = "Ar" Then
TextBox1.Value = ""
ChangeButton.Visible = False
End If
If ComboBox1.Value = "Vapor / ?gua" Then
TextBox1.Value = ""
If Folha1.Cells(16, 11) <> 1 Then UserForm4.Show
ChangeButton.Visible = True
End If
If ComboBox1.Value = "Gases de escape" Then
TextBox1.Value = ""
If Folha1.Cells(16, 11) <> 1 Then UserForm7.Show
ChangeButton.Visible = True
End If
If ComboBox1.Value = "Personalizar" Then
TextBox1.Enabled = True
CommandButton1.Enabled = True
ChangeButton.Visible = True
Else
TextBox1.Enabled = False
CommandButton1.Enabled = False
ChangeButton.Visible = False
End If
End Sub



where ChangeButton is a button next to the Combobox

mqdias
11-06-2007, 08:22 AM
what do you mean by ChangeButton? I don't have that in my toolbox. Only command buttons.

My last question is not how to call the funtion, but what is the VB code that makes the same as if i clicked in a command button (but without clicking in it).

figment
11-06-2007, 08:38 AM
ChangeButton is simply a renamed Command button.

i am not sure what you mean by clicking the button without clicking it. sounds like you need to find a event to call your sub from, i would sugest skimming through the event subs till you find the one you need.

mqdias
11-06-2007, 08:47 AM
Ok. I think i know what to do: use the "call" to generate a click event.

So, thank you soo much for your suggestions. They were very helpfull!!!