Ark68
Well-known Member
- Joined
- Mar 23, 2004
- Messages
- 4,570
- Office Version
- 365
- 2016
- Platform
- Windows
Considering this code:
If the user enters a bad value in textbox "tb_r1_sru", it triggers the badtime: event. Within that code, a msgbox appears and the value is cleared. The intention is to return the user back to that textbox to allow them to reenter a value. I thought that's what the "SetFocus" would accomplish for me.
What ends up happening is the cursor appears in textbox 'tb_r1_srl' in that same form . The user has to click back into "tb_r1_sru" in order to reenter a value. I added mbevents = false to prevent the code from the BeforeUpdate event of 'Me.tb_r1_srl' from running in case that may be why the cursor insists of going there.
Is anyone able to provide a reason why this may be happening?
Code:
Private Sub tb_r1_sru_BeforeUpdate(ByVal CANCEL As MSForms.ReturnBoolean)
'Stop
On Error GoTo badtime
Me.tb_r1_sru.Value = format(Me.tb_r1_sru.Value, "h:mm AM/PM")
sru1 = CDate(tb_r1_sru.Value)
chk1 = sru1
time_range1 chk1
mbevents = false
If e = 1 Then
Me.tb_r1_sru.Value = ""
Me.tb_r1_sru.SetFocus
Else
Me.tb_r1_srl.Value = format(sru1 + TimeSerial(0, 30, 0), "h:mm AM/PM")
buv = CDate(tb_r1_srl.Value)
End If
mbevents = true
Exit Sub
badtime:
MsgBox "Invalid time."
Me.tb_r1_sru.Value = ""
Me.tb_r1_sru.SetFocus
End Sub
If the user enters a bad value in textbox "tb_r1_sru", it triggers the badtime: event. Within that code, a msgbox appears and the value is cleared. The intention is to return the user back to that textbox to allow them to reenter a value. I thought that's what the "SetFocus" would accomplish for me.
What ends up happening is the cursor appears in textbox 'tb_r1_srl' in that same form . The user has to click back into "tb_r1_sru" in order to reenter a value. I added mbevents = false to prevent the code from the BeforeUpdate event of 'Me.tb_r1_srl' from running in case that may be why the cursor insists of going there.
Is anyone able to provide a reason why this may be happening?