Require User inputs to continue

J

Jeremy

So I have a userform with 5 comboboxes with selections that need to be made.
At the bottom are the buttons "next" "cancel" and "help".

I want to have the "next" button disabled until the user has made a
selection (any selection) in each combobox, then I want it enabled.

I figured I could have the next button check to see if anything is not
selected, but that only works on a click...
 
P

Patrick Molloy

create a function:

Sub CheckCombos()
btnNext.Enabled = False
if combobox1.ListIndex=-1 then exit sub
if combobox2.ListIndex=-1 then exit sub
if combobox3.ListIndex=-1 then exit sub
if combobox4.ListIndex=-1 then exit sub
if combobox5.ListIndex=-1 then exit sub
btnNext.Enabled = True
End sub

2) now have each listbox change event call this sub
 
J

Jim Thomlinson

Write a procedure that checks the value of all 5 combo boxes and enables the
next button if all 5 have been completed. Now just call that procedure on
combo box change... Something like this...

Private Sub ComboBox1_Change()
Call EnableNext
End Sub

Private Sub ComboBox2_Change()
Call EnableNext
End Sub

Private Sub EnableNext()
If CBool(Len(Trim(ComboBox1.Text))) And _
CBool(Len(Trim(ComboBox2.Text))) Then
CommandButton1.Enabled = True
Else
CommandButton1.Enabled = False
End If
End Sub
 
R

Rick Rothstein

Assuming your ComboBoxes are named ComboBox1, ComboBox2, etc. and that your
Next button is named CommandButton1, put this code into the UserForm's code
window (removing any of your own code for these events first)...

Private Sub ComboBox1_Change()
CommandButton1.Enabled = IsCBsSelected
End Sub

Private Sub ComboBox2_Change()
CommandButton1.Enabled = IsCBsSelected
End Sub

Private Sub ComboBox3_Change()
CommandButton1.Enabled = IsCBsSelected
End Sub

Private Sub ComboBox4_Change()
CommandButton1.Enabled = IsCBsSelected
End Sub

Private Sub ComboBox5_Change()
CommandButton1.Enabled = IsCBsSelected
End Sub

Private Sub UserForm_Initialize()
CommandButton1.Enabled = False
End Sub

Function AreComboBoxesSelected() As Boolean
IsCBsSelected = (ComboBox1.Text <> "") + (ComboBox2.Text <> "") + _
(ComboBox3.Text <> "") + (ComboBox4.Text <> "") + _
(ComboBox5.Text <> "") = 5
End Function
 

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