Userform - Make select field required for submission - 1 message containing all errors

JustHooch

New Member
Joined
May 17, 2018
Messages
44
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 -
  • 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.
  1. 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
  2. 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
  3. 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:
I tried this for like an hour before I reposted. I got your response and was like ok let me try one more time since it really is that easy....and wouldn't you know it.....it worked. *sigh* maybe I need to be done with coding for the day. LOL Thank you so much for all your help today.
 
Upvote 0

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
You're welcome.
Glad you got it sorted.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top