Preventing incorrect data entry

Big Lar

Well-known Member
Joined
May 19, 2002
Messages
557
I need to prevent users from entering incorrect values.
Everything works except SetFocus.
Any suggestions?

Rich (BB code):
Private Sub TextBox2_AfterUpdate()
CheckBox3.Value = True

If (Me.TextBox2.Value) <= (Me.TextBox1.Value) Then

MsgBox "Value Cannot Be Less Than 1st Flight", vbCritical
TextBox2.Value = ""
TextBox2.SetFocus

Exit Sub
Else

Label3 = TextBox2.Value + 1 & " To:"
End If

End Sub
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Assuming you are working with Userform1 try adding an ontime routine in a new Standard Module like this :
Code:
Sub SetFocusBack(ByVal TextBoxName As String)
    UserForm1.TextBox2.SetFocus
End Sub

And then change your original code to this :
Code:
Private Sub TextBox2_AfterUpdate()

    CheckBox3.Value = True
    If (Me.TextBox2.Value) <= (Me.TextBox1.Value) Then
        [B][COLOR=#0000ff]Application.OnTime Now, "'SetFocusBack ""TextBox2""'"[/COLOR][/B]
        MsgBox "Value Cannot Be Less Than 1st Flight", vbCritical
        TextBox2.Value = ""
        Exit Sub
    Else
        Label3 = TextBox2.Value + 1 & " To:"
    End If

End Sub
 
Last edited:
Upvote 0
Maybe
Code:
Me.TextBox2.SetFocus[COLOR=#ff0000]
[/COLOR]
 
Upvote 0
Maybe
Code:
Me.TextBox2.SetFocus[COLOR=#ff0000]
[/COLOR]

JLGWhiz,
Thanks for the suggestion. I tried that yesterday and it failed to resolve the issue.
Oddly, it works on other procedures in my project. (Confused)
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,249
Members
452,623
Latest member
Techenthusiast

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top