H
Hendy88
Hello all,
I have a Private Exit Sub for a Textbox that forces a person to enter
information in this box FIRST, before clicking into other parts of the
form. Basically, it's an employee time tracking form, and I've done
it this way because after they enter their employee number to start
off, it then goes up against another spreadsheet to bring back how
many vacation hours they have accrued to use up for the year. So this
way, they have to enter their number first in order to show what they
have, otherwise they have no business clicking around in other fields
and yada yada yada
Anyway, the question/problem I have is this: Once the userform is
displayed, I have part of the "verification" checking to see if they
left that textbox blank, and if they did it's shows a MsgBox that
says,
"Employee number field cannot be left blank. Please enter a valid
number."
Which works just fine, but if they click the "X" in the corner of the
userform to exit, it closes the form (which is what it's supposed to
do), but then because they left the textbox blank, after the forms
closes it still shows the message box telling them that the employee
field cannot be left blank.
Is there a way in the Private Exit Sub to specify, that IF the person
is "exiting" the textbox by clicking on the "X" to close, then not to
display the MsgBox?
Something like:
Private Sub EmpNum_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If EmpNum.Value = "" AND (Close Button is Clicked) Then
(Close UserForm without MsgBox)
Else
MsgBox "Employee number field cannot be left blank. Please
enter a valid number."
End If
End Sub
I have a Private Exit Sub for a Textbox that forces a person to enter
information in this box FIRST, before clicking into other parts of the
form. Basically, it's an employee time tracking form, and I've done
it this way because after they enter their employee number to start
off, it then goes up against another spreadsheet to bring back how
many vacation hours they have accrued to use up for the year. So this
way, they have to enter their number first in order to show what they
have, otherwise they have no business clicking around in other fields
and yada yada yada
Anyway, the question/problem I have is this: Once the userform is
displayed, I have part of the "verification" checking to see if they
left that textbox blank, and if they did it's shows a MsgBox that
says,
"Employee number field cannot be left blank. Please enter a valid
number."
Which works just fine, but if they click the "X" in the corner of the
userform to exit, it closes the form (which is what it's supposed to
do), but then because they left the textbox blank, after the forms
closes it still shows the message box telling them that the employee
field cannot be left blank.
Is there a way in the Private Exit Sub to specify, that IF the person
is "exiting" the textbox by clicking on the "X" to close, then not to
display the MsgBox?
Something like:
Private Sub EmpNum_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If EmpNum.Value = "" AND (Close Button is Clicked) Then
(Close UserForm without MsgBox)
Else
MsgBox "Employee number field cannot be left blank. Please
enter a valid number."
End If
End Sub