Ark68
Well-known Member
- Joined
- Mar 23, 2004
- Messages
- 4,564
- Office Version
- 365
- 2016
- Platform
- Windows
Here is my userform initialization code:
When the form is launched, controls are set as above. There is a second commandbutton called "EMPL_EXIT" that when clicked exits and closes the userform. On launch, the cursor is blinking waiting for entry into me.empl_surname, the only textbox accessible. (the other 3 are disabled).
Here is my me.empl_surname exit code:
The problem I am here looking for help with is that at this point after the form is launched (no entry into me.empl_surname), I cannot click the EXIT button to leave the userform. Evertime I try, the me.emply_surname exit triggers and I get "Enter the employee's surname. This cannot be empty.). It becomes an endless cycle.
The only way I can use the EXIT button at this stage is to enter a value in me.empl_surname, then the EXIT button works.
My exit button:
Code:
Private Sub UserForm_Initialize()
Call SystemButtonSettings(Me, False)
mbevents = True
Me.cb_wc_sc.Value = False
Me.cb_wc_wp.Value = False
Me.empl_surname.Value = ""
Me.empl_given.Value = ""
Me.empl_number.Value = "00000"
Me.empl_shift.Value = "[1] 7:00A - 3:00P"
cb_tally = 0
txt_tally = 0
all_tally = 0
Me.EMPL_SUBMIT.Enabled = False
Me.empl_given.Enabled = False
Me.empl_number.Enabled = False
Me.empl_shift.Enabled = False
Me.cb_wc_sc.Locked = True
Me.cb_wc_wp.Locked = True
Me.cb_wc_fh.Locked = True
End Sub
When the form is launched, controls are set as above. There is a second commandbutton called "EMPL_EXIT" that when clicked exits and closes the userform. On launch, the cursor is blinking waiting for entry into me.empl_surname, the only textbox accessible. (the other 3 are disabled).
Here is my me.empl_surname exit code:
Code:
Private Sub empl_surname_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Dim strData As String
'Stop
'invalid entry
'null
If empl_surname.Value = "" Then
MsgBox "Enter the employee's surname. This cannot be left empty.", vbExclamation, "Invalid Entry [SURNAME]"
empl_surname = ""
Cancel = True
Exit Sub
End If
If Len(empl_surname.Value) < 2 Then
MsgBox "Enter the employee's surname." & Chr(13) & "(Min. 2 letters)", vbExclamation, "Invalid Entry [SURNAME]"
empl_surname = ""
Cancel = True
Exit Sub
End If
strData = empl_surname.Value
If HasNumber(strData) = True Then
MsgBox "Enter the employee's surname without numbers.", vbExclamation, "Invalid Entry [SURNAME]"
empl_surname = ""
Cancel = True
Exit Sub
End If
'valid entry
'Stop
txt_tally = 0
cb_tally = 0
For Each ctrl In Me.Controls
Debug.Print TypeName(ctrl)
If TypeName(ctrl) = "TextBox" Then
If ctrl.Value <> "" Then txt_tally = txt_tally + 1
ElseIf TypeName(ctrl) = "CheckBox" Then
If ctrl.Value = True Then cb_tally = cb_tally + 1
End If
Next ctrl
If Me.empl_number.Value = "00000" Then txt_tally = txt_tally - 1
all_tally = txt_tally + cb_tally
If all_tally = 4 Then
Me.EMPL_SUBMIT.Enabled = True
End If
Me.empl_given.Enabled = True
End Sub
The problem I am here looking for help with is that at this point after the form is launched (no entry into me.empl_surname), I cannot click the EXIT button to leave the userform. Evertime I try, the me.emply_surname exit triggers and I get "Enter the employee's surname. This cannot be empty.). It becomes an endless cycle.
The only way I can use the EXIT button at this stage is to enter a value in me.empl_surname, then the EXIT button works.
My exit button:
Code:
Private Sub EMPL_EXIT_Click()
Stop
Application.ScreenUpdating = False
mbevents = False
With ws_gui
.Unprotect
.Range("M2").Value = "- Select operator -"
.Protect
End With
mbevents = True
Application.ScreenUpdating = True
Unload Me
End Sub