Ark68
Well-known Member
- Joined
- Mar 23, 2004
- Messages
- 4,564
- Office Version
- 365
- 2016
- Platform
- Windows
I have a userform with a couple textboxes, a 'SUBMIT' button (commandbutton1) which advances the code to the next process after the user enters a value in the textbox, and a 'CANCEL' button (commandbutton2) which cancels the user's ability to enter a value by closing the userform.
I am having a problem. When the 'CANCEL' button is selected, the textbox exit event is triggered with the userform closing.
Userform initialization ...
The commandbutton 'CANCEL' code
The textbox exit code being executed when CANCEL button is selected...
I am having a problem. When the 'CANCEL' button is selected, the textbox exit event is triggered with the userform closing.
Userform initialization ...
Code:
Private Sub UserForm_Initialize()
Dim l_rid As Long
Dim rn As Double
mbEvents = True
Set ws_vh = Workbooks("Sports15b.xlsm").Worksheets("VAR_HOLD")
fn = ws_vh.Range("B3")
Set ws_core = Workbooks(fn).Worksheets("CORE")
l_rid = ws_vh.Range("B13")
rn = ws_core.Range("A:A").Find(l_rid).Row
If ws_core.Range("DP" & rn) > 0 Then '(1)
MsgBox "Services already processed"
With trn_reline
' --- 1 ---
.tb_r1_srl.Value = ws_core.Range("BK" & rn)
.tb_r1_sru.Value = ws_core.Range("BL" & rn)
.cb_r1_division = ws_core.Range("BN" & rn)
.cb_r1_base.Value = ws_core.Range("BO" & rn)
.cb_r1_pitch.Value = ws_core.Range("BP" & rn)
.cb_r1_crew.Value = ws_core.Range("BQ" & rn)
If ws_core.Range("BM" & rn) > 0 Then
.ob_r1_reline.Value = True
.ob_r1_change.Value = False
.cb_r1_base.Enabled = False
.cb_r1_pitch.Enabled = False
Else
.ob_r1_reline.Value = False
.ob_r1_change.Value = True
.cb_r1_base.Enabled = True
.cb_r1_pitch.Enabled = True
End If
' --- 2 ---
.tb_r2_srl.Value = ws_core.Range("BR" & rn)
.tb_r2_sru.Value = ws_core.Range("BS" & rn)
.cb_r2_division = ws_core.Range("BU" & rn)
.cb_r2_base.Value = ws_core.Range("BV" & rn)
.cb_r2_pitch.Value = ws_core.Range("BW" & rn)
.cb_r2_crew.Value = ws_core.Range("BX" & rn)
If ws_core.Range("BT" & rn) > 0 Then
.ob_r2_reline.Value = True
.ob_r2_change.Value = False
.cb_r2_base.Enabled = False
.cb_r2_pitch.Enabled = False
Else
.ob_r2_reline.Value = False
.ob_r2_change.Value = True
.cb_r2_base.Enabled = True
.cb_r2_pitch.Enabled = True
End If
End With
End If '(1)
mbEvents = True
End Sub
The commandbutton 'CANCEL' code
Code:
Private Sub rl_cancel_Click()
Unload Me
End Sub
The textbox exit code being executed when CANCEL button is selected...
Code:
Private Sub tb_r1_sru_Exit(ByVal CANCEL As MSForms.ReturnBoolean)
If mbEvents Then Exit Sub
mbEvents = True
If IsDate(Me.tb_r1_sru.Value) Then
Me.tb_r1_sru.Value = Format(Me.tb_r1_sru.Value, "h:mm AM/PM")
Else
MsgBox "Please enter a valid time (eg. '24:00' or '12:00 PM')"
Me.tb_r1_sru.Value = ""
CANCEL = True
End If
mbEvents = False
End Sub