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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can I Disable An Excel UserForm Button Until Both Combo Boxes Are Populated? 2

Status
Not open for further replies.

PWD

Technical User
Jul 12, 2002
823
0
0
GB
Good afternoon. I have created a Userform - "Form1" - that contains 2 x Combo boxes - "MonthComboBox" & "WeekComboBox", 2 x text boxes (effectively labels) and 1 x Command Button - called "Rename". This form is 'called' from a button on the workbook that just runs the code:

Code:
Form1.Show

My colleague came up with the idea (just now!) of putting this in the "ThisWorkbook" module:

Code:
Form1.Rename.Enabled = False

And then these behind the Combo boxes:

Code:
Private Sub MonthComboBox_Change()

  If Form1.MonthComboBox.Text <> "" And Form1.WeekComboBox.Text <> "" Then

    Form1.Rename.Enabled = True
Else
    Form1.Rename.Enabled = False
    
End If

End Sub

Private Sub WeekComboBox_Change()

  If Form1.MonthComboBox.Text <> "" And Form1.WeekComboBox.Text <> "" Then

    Form1.Rename.Enabled = True
Else
    Form1.Rename.Enabled = False
    
End If

End Sub

Does this sound like a good approach? I had thought of just disabling the button via its properties.

Many thanks,
D€$
 
If I were going down that route I'd be tempted to simplify the code to:

Code:
[blue]Option Explicit

Private Sub UserForm_Activate()
    ToggleButton
End Sub

Private Sub MonthComboBox_Change()
    ToggleButton
End Sub

Private Sub WeekComboBox_Change()
    ToggleButton
End Sub

Private Sub ToggleButton()
    Rename.Enabled = MonthComboBox.Text <> "" And WeekComboBox.Text <> ""
End Sub[/blue]
 
Hi strongm, thanks for this.

Many thanks,
D€$
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top