Ark68
Well-known Member
- Joined
- Mar 23, 2004
- Messages
- 4,564
- Office Version
- 365
- 2016
- Platform
- Windows
I have this (exit event) code that error checks the value entered into a textbox (tb_pn) on my userform. This textbox is in focus when the userform opens.
On my userform, I also have an "Exit" button. This exit button simply closes the userform.
But when I click the Exit Button, the, exit event code for tb_pn triggers. Is there a better event to use for triggering the error checking code? What can I do to avoid this behaviour?
On my userform, I also have an "Exit" button. This exit button simply closes the userform.
But when I click the Exit Button, the, exit event code for tb_pn triggers. Is there a better event to use for triggering the error checking code? What can I do to avoid this behaviour?
Code:
Private Sub tb_pn_exit(ByVal Cancel As MSForms.ReturnBoolean) 'beforeupdate(ByVal Cancel As MSForms.ReturnBoolean)
If Not mbevents Then Exit Sub
If Len(tb_pn) > 7 Or Len(tb_pn) < 5 Then
MsgBox "Please enter a valid permit number {R####..}.", vbExclamation, "PERMIT NUMBER ERROR"
ElseIf Right(tb_pn, 1) <> "R" Then
MsgBox "Please enter a valid permit number {R####..}.", vbExclamation, "PERMIT NUMBER ERROR"
ElseIf Len(tb_pn) - 1 < 4 Or Len(tb_pn) - 1 > 6 Then
MsgBox "Please enter a valid permit number {R####..}.", vbExclamation, "PERMIT NUMBER ERROR"
nom = Left(tp_pn, lentp_pn - 1)
ElseIf IsError(CDbl(nom)) Then
MsgBox "Please enter a valid permit number {R####..}.", vbExclamation, "PERMIT NUMBER ERROR"
Else
Me.tb_pn.BackColor = vbWhite
Me.cbx_rcode.BackColor = clr_blue
End If
End Sub