Search code examples
ms-accessvbams-access-2016

Move to next control at end of string


I have a form with a control that has a mask. The mask accepts 10 numbers, I have them formatted as short text. I will not be doing any calculation on them. They are just a string of numbers. I want the control to change focus to another control when I enter that last character. Example: I enter 1111-10-1234, when I type 4, I want the focus to change to the next control. I tried to use Len to change focus but it always shows the length as 12 since I have 12 place holders. Any other suggestions.


Solution

  • You might use the SelStart property:

    If Me!YourTextBox.SelStart = 12 Then
        ' Cursor has moved past the last position.
        Me!SomeOtherControl.SetFocus
    End If