On a continuous Form, I'd like - if possible - to be able enter two digits in intField1 and - without having to hit the Tab key, or click on txtField2, etc - to have the focus set to txtField2. Is that achievable.......in VBA or otherwise (maybe via a Validation Rule) ? I've been trying the code below with After_Update, Before_Update, On_Dirty... but can't get anything to work. Can it be done ?
If Len(Me.intField1.Value) = 2 Then
Me.txtField2.SetFocus
End If
If that is a text box for input, you can look at the "OnChange" event as a way to note that two non-blank characters have been entered, because the OnChange event triggers for each keystroke. You can check the control.Text property each time a key is entered to see what is in the box. Then you can decide what to do after each keystroke, including a .SetFocus to something else. The down side of this is that your user could backspace to remove the first character, but the second character would not be correctable so easily.
Thanks for your response, Josef. There's no input mask, as intField1 is Number data type. One can't set an input mask on a field of Number data type, right ?
The code needs to reference the .Text property and the code needs to go into the control's Change Event.
Code:
If Len(Me.intField1.Text) = 2 Then
Me.txtField2.SetFocus
End If
Each text control has THREE buffers
.OldValue - whatever is in the saved version of the record. Always Null for a new record.
.Text - the typing buffer. As each character is typed, the character is placed into this buffer and the Change event is called.
.Value - after data entry is complete, and focus has moved, the .Text buffer is copied to the .Value buffer.
Between the form's BeforeUpdate event and its AfterUpdate event, data is copied from the .Value buffer to the .OldValue buffer
WHENEVER you use the Change event, you need to reference the .Text buffer to see the live typing BEFORE it gets moved to the .Value buffer. If you reference the .Value buffer from the Change event, you will see what was there previously, usually the same as the .OldValue unless the user has modified the data in the control more than once before saving. In older versions of Access, you would get an error if you referenced the .Text property from any event except the Change event. Newer versions seem to be more forgiving of that error. But they can't detect the mistake of using .Value in the Change event instead of .Text because you may actually want to refer to the .Value property.
Thanks ever so much, Pat. That worked really well with my numeric field. Josef and The_Doc_Man : thanks to you too; your suggestions have resolved some other elements I'm working on.