View Full Version : Solved: how to buttom changed from inactive to active
helai
06-10-2006, 06:15 PM
I create a userform includes three comboboxes and OK(button) CANCLE(button)
Now I want to have this effection
When USERFORM inistalized ,the ok button turned into inactive,and when I input data into three comboboxes,then the status of ok turned into active automatically
how to write the code?
any advices are welcome
HELAI
************************
thank you very soon reply
malik641
06-10-2006, 06:28 PM
This is just a small example with some arrogance :cool:
Option Explicit
Private Sub ComboBox1_Change()
If ComboBox1.Value <> "" And ComboBox2.Value <> "" And ComboBox3.Value <> "" Then
CommandButton1.Enabled = True
Else
CommandButton1.Enabled = False
End If
End Sub
Private Sub ComboBox2_Change()
If ComboBox1.Value <> "" And ComboBox2.Value <> "" And ComboBox3.Value <> "" Then
CommandButton1.Enabled = True
Else
CommandButton1.Enabled = False
End If
End Sub
Private Sub ComboBox3_Change()
If ComboBox1.Value <> "" And ComboBox2.Value <> "" And ComboBox3.Value <> "" Then
CommandButton1.Enabled = True
Else
CommandButton1.Enabled = False
End If
End Sub
Private Sub CommandButton2_Click()
Me.Hide
End Sub
Private Sub Userform_Initialize()
ComboBox1.AddItem ("Joe")
ComboBox2.AddItem ("is")
ComboBox3.AddItem ("cool.")
CommandButton1.Enabled = False
End Sub
mdmackillop
06-11-2006, 03:16 AM
Just for compactness, I would put Josephs main code in a separate sub.
Option Explicit
Private Sub Userform_Initialize()
ComboBox1.AddItem ("Joe")
ComboBox2.AddItem ("is")
ComboBox3.AddItem ("cool.")
CommandButton1.Enabled = False
End Sub
Private Sub CommandButton2_Click()
Me.Hide
End Sub
Private Sub ComboBox1_Change()
SetButton
End Sub
Private Sub ComboBox2_Change()
SetButton
End Sub
Private Sub ComboBox3_Change()
SetButton
End Sub
Private Sub SetButton()
If ComboBox1.Value <> "" And ComboBox2.Value <> "" And ComboBox3.Value <> "" Then
CommandButton1.Enabled = True
Else
CommandButton1.Enabled = False
End If
End Sub
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.