J
JT
I'm using the code below to check the value a user has entered in a textbox
(TB10) when they move to the next textbox (TB11). It is checking the value
against a list of accounts on the "Macros" sheet.
The problem I am having is that the cursor moves to TB11 when "Proceed =
False" instead of to TB10. I want the cursor to move back to TB10 so the
user can try to enter a valid account again before moving on to the next
textbox. I thought TB10.SetFocus would do the trick but I can't get it to
work.
Any help in getting the cursor to TB10 would be greatly appreciated.
Private Sub TB10_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Cancel = False
TB10_LostFocus
Dim CheckThis As String
Dim Proceed As Boolean
CheckThis = ""
Proceed = False
CheckThis = TB10
If Len(CheckThis) < 4 Then
Do Until Len(CheckThis) = 4
CheckThis = "0" & CheckThis
Loop
End If
Dim r As Integer
r = 1
Do Until Len(Trim(Worksheets("Macros").Cells(r, 26))) = 0
If CheckThis = Worksheets("Macros").Cells(r, 26) Then
Proceed = True
End If
r = r + 1
Loop
If Proceed = False Then
TB10 = ""
TB10.SetFocus
Exit Sub
End If
End Sub
(TB10) when they move to the next textbox (TB11). It is checking the value
against a list of accounts on the "Macros" sheet.
The problem I am having is that the cursor moves to TB11 when "Proceed =
False" instead of to TB10. I want the cursor to move back to TB10 so the
user can try to enter a valid account again before moving on to the next
textbox. I thought TB10.SetFocus would do the trick but I can't get it to
work.
Any help in getting the cursor to TB10 would be greatly appreciated.
Private Sub TB10_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Cancel = False
TB10_LostFocus
Dim CheckThis As String
Dim Proceed As Boolean
CheckThis = ""
Proceed = False
CheckThis = TB10
If Len(CheckThis) < 4 Then
Do Until Len(CheckThis) = 4
CheckThis = "0" & CheckThis
Loop
End If
Dim r As Integer
r = 1
Do Until Len(Trim(Worksheets("Macros").Cells(r, 26))) = 0
If CheckThis = Worksheets("Macros").Cells(r, 26) Then
Proceed = True
End If
r = r + 1
Loop
If Proceed = False Then
TB10 = ""
TB10.SetFocus
Exit Sub
End If
End Sub