Userform - All fields Manadatory and must me Completed yet "Unload Me" circumvents process

Dice711

New Member
Joined
Aug 13, 2002
Messages
14
Hello

Need help on this one. I have really tried to search and figure this issue out before posting...

I have a userform called DigitalSignatureSM that is used to digitally sign a form. All fields in the userform (i.e. dropdown combo boxes) are required to be filled and will highlight in red the areas that need to be filled in and will not let the user proceed until all required fields have information (see that code below). I call the userform into subroutine using: DigitalSignatureSM.Show.

Everything works fine unless the user decides to click on the "Close" button on the userform that is actually just "Unload Me." The problem is that the original subroutine continues on and processes the code to the end, whereby giving my an un-signed form. What I really want to happen is if the user clicks on the "Close" button (or otherwise Unload Me), that all code stops meaning the userform closes (that happens now) and everything stops (that doesn't happen).

Thanks in advance for any help. I hope it is something simple...


Make all fields mandatory code:

Dim ans As Long
For Each ctrl In Me.Controls
Select Case True
Case TypeOf ctrl Is MSForms.CheckBox, TypeOf ctrl Is MSForms.OptionButton
Select Case ctrl.Value
Case True
ctrl.BackColor = vbGreen
Case Else
ctrl.BackColor = vbRed: ans = ans + 1
End Select
Case TypeOf ctrl Is MSForms.TextBox, TypeOf ctrl Is MSForms.ComboBox
Select Case ctrl.Value
Case vbNullString
ctrl.BackColor = vbRed: ans = ans + 1
Case Else
ctrl.BackColor = vbGreen
End Select
End Select
Next ctrl
If ans > 0 Then
MsgBox "Please enter data in the required fields. Controls in Red need completion", vbInformation, "Enter Data"
Exit Sub
'Else
'MsgBox "Thanks, fields have been filled correctly"
End If
 
in your first post you stated

I call the userform into subroutine using: DigitalSignatureSM.Show.

and for this my suggestion included these lines

Code:
    DigitalSignatureSM.Show
    If CancelEntry Then Exit Sub


where in your project are these lines included?

Dave
 
Upvote 0

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Hello Dave

Thanks again for all of your help on this problem. I actually fixed it by entering a small "If" function into the main working code:

Code:
If Range("CurrentNameSM") = "" Or Range("CurrentNameGR") = "" Or Range("CurrentCheckBox") = "" Then
    
    MsgBox "You did not complete the Digital Signature process correctly, please click blue GO>> button and start over", vbCritical, "Process Stopped"
    
    Exit Sub
        
    Else
    
    End If

Basically if any of the fields are empty, it will Exit Sub.

Thanks again!!!
 
Upvote 0

Forum statistics

Threads
1,214,864
Messages
6,121,986
Members
449,058
Latest member
oculus

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