Making multiple ComboBoxes mandatory

T

thinblueline

I have three comboboxes in a userform, is it possible to make
combobox2 and 3 mandatory when combobox1 is not empty?
 
D

Doug Robbins - Word MVP on news.microsoft.com

Check the .ListIndex attribute of the comboboxes. If it returns -1, display
a message box telling the user that they must make a selection from the
combobox concerned.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
 
T

thinblueline

Check the .ListIndex attribute of the comboboxes.  If it returns -1, display
a message box telling the user that they must make a selection from the
combobox concerned.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com

I was able figure out how to get combobox2 to be required if combobox1
is not empty, but I can't seem to figure out how to also get combobox3
to do the same.

Private Sub CommandButton1_Click()
If ComboBox1.ListIndex <> -1 And ComboBox2.ListIndex = -1 Then
MsgBox "Box2 is Required"
ComboBox2.SetFocus
Else
Unload Me
End If
 
J

Jay Freedman

thinblueline said:
I was able figure out how to get combobox2 to be required if combobox1
is not empty, but I can't seem to figure out how to also get combobox3
to do the same.

Private Sub CommandButton1_Click()
If ComboBox1.ListIndex <> -1 And ComboBox2.ListIndex = -1 Then
MsgBox "Box2 is Required"
ComboBox2.SetFocus
Else
Unload Me
End If

Check each one individually:

If ComboBox1.ListIndex <> -1 Then
If ComboBox2.ListIndex = -1 Then
MsgBox "Box2 is Required"
ComboBox2.SetFocus
Exit Sub
End If

If ComboBox3.ListIndex = -1 Then
MsgBox "Box3 is Required"
ComboBox3.SetFocus
Exit Sub
End If
End If

' If neither Exit Sub was executed, you get here
Unload Me

End Sub

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 
D

Doug Robbins - Word MVP on news.microsoft.com

Use the same construction again with Combobox2 replaced by Combobox3

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com

Check the .ListIndex attribute of the comboboxes. If it returns -1,
display
a message box telling the user that they must make a selection from the
combobox concerned.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com

I was able figure out how to get combobox2 to be required if combobox1
is not empty, but I can't seem to figure out how to also get combobox3
to do the same.

Private Sub CommandButton1_Click()
If ComboBox1.ListIndex <> -1 And ComboBox2.ListIndex = -1 Then
MsgBox "Box2 is Required"
ComboBox2.SetFocus
Else
Unload Me
End If
 
T

thinblueline

Use the same construction again with Combobox2 replaced by Combobox3

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com






I was able figure out how to get combobox2 to be required if combobox1
is not empty, but I can't seem to figure out how to also get combobox3
to do the same.

Private Sub CommandButton1_Click()
If ComboBox1.ListIndex <> -1 And ComboBox2.ListIndex = -1 Then
  MsgBox "Box2 is Required"
  ComboBox2.SetFocus
Else
  Unload Me
End If

Jay and Doug, thank you.
 

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