View Full Version : Highlight text after validation fails?
Terabyte
07-13-2006, 10:50 AM
I'm using Access 2000 and I am curious to know if there is a way to highlight the text field so it is immediately ready for editing after the validation rule is violated.
Example:
Number field requires 10 numbers, user only puts 9, then tabs, they receive error msg, and the insertion point it put at the beginning of the field. I would like for the entire field to be highlighted automatically without the need to have the user select it.
I've searched the forums here and other places and have had no luck, any guidance would be appreciated.
Thank you.
You use the Set Focus method to move the Cursor back to the field in question.
Like this
Me.CategoryName.SetFocus
this moves the focus to a field called CategoryName on the active Form.
asingh
07-13-2006, 07:45 PM
I tried the logic as per OBP. If I have a 2nd text box..next to the one..which has the setup for 10 numbers..the cursor still jumps ahead...! I was using the following..on the exit event of the text box:...
Private Sub Text0_Exit(Cancel As Integer)
Dim UsrEntyLn As Integer
Dim UsrEntVal As String
UsrEntVal = Me.Text0.Text
UsrEntyLn = Len(UsrEntVal)
If UsrEntyLn <> 10 Then
Me.Text0.SetFocus
End If
End Sub
Cosmos75
07-13-2006, 07:46 PM
As OBP said, you can use .SetFocus to bring the user back to the offending field. If you are using Access 2000 and higher, you can use Conditional Formatting to highlight that field when it has the focus, but it will work for every record regardless of whether there is an validation error.
If your validation isn't too complicated, you can incorporate that into the conditional formatting. Keep in mind you are limted to three conditions, and the first condition is the only one that can be used to set the format when the field has the focus.
I am not sure that you can use the .setfocus on the exit of a field, you may be better off moving the validation to the form's Before Update event procedure because then the last field on the form will have the focus and it should move back to the Text0 field.
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.