I have 2 wants (1) to make only select fields required for submission on my userform (2) to have a single Message box that contains all the errors listed.
Userform details -
The below is what I have worked out so far but it has some issues.
I would like to get all the required fields in one line of logic that will provide the user with a list of all the fields that are missing data in one message box. Is this possible?
Userform details -
- Submission happens when the CommandButtonSubmit is clicked
- Required fields include textboxes, comboboxes and frames containing checkboxes where at least 1 selection must be made
The below is what I have worked out so far but it has some issues.
- The code for "That one option is checked for Offer Contains" will check the frame and display a message is not checkboxes = true but will not stop the form from being submitted
- The code for "That one option is checked for Offer Contains" is separate from the code "All other required fields", which means if both codes have blank fields then I get 2 separate message boxes
- The code for "All other required fields" only gives the user the first fail message no matter how many fields are blanks
- So for the below, if the user has both OfferName and OfferType blank when they click on submit they will get a message that "Offer name is required" only
- They will enter the offer name, hit submit again only then will they get the message about the Offer Type
I would like to get all the required fields in one line of logic that will provide the user with a list of all the fields that are missing data in one message box. Is this possible?
Code:
'When Click Submit button
Private Sub CommandButtonSubmit_Click()
'Check for Required fields
'That one option is checked for Offer Contains
For Each ctrl In FrameContains.Controls
If TypeOf ctrl Is msforms.CheckBox Then
If ctrl.Value = True Then
F1D = True
Exit For
End If
End If
Next ctrl
If F1D = False Then
MsgBox "No Option Selected for Offer Contains (Pick all that Apply)"
End If
'All other required fields
With Me[INDENT]If TextBoxOfferName.Value = "" Then[/INDENT]
MsgBox "Offer Name is required"
Exit Sub
ElseIf ComboBoxOfferType = "" Then
MsgBox "Offer Type is required"
Exit Sub
End If
End With
'Make Ticket Tab active
Sheets("Ticket Offer Info").Activate
'Transfer Segment Selections
myVar = ""
For x = 0 To Me.ListBoxSegment.ListCount - 1
If Me.ListBoxSegment.Selected(x) Then
If myVar = "" Then
myVar = Me.ListBoxSegment.List(x, 0)
Else
myVar = myVar & "," & Me.ListBoxSegment.List(x, 0)
End If
End If
Next x
Range("B5").Value = myVar
'Transfer all other information to Ticket Tab
Range("B3").Value = TextBoxOfferName[INDENT]'have lots more that feeds but took out to save space[/INDENT]
Unload Me
End Sub
Last edited: