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
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