When tabbing between Controls on Forms and they contain text all the data within the Control is selected. This can be problematic as Users may inadvertently overwrite what is already there and not even realize it as they begin typing. To avoid that you can force the Cursor to land at the beginning or the end of the Control by using one of the below Sub’s. For example, for Controls where the Date is entered I prefer to have the User start at the beginning, however, if entering notes I put the Cursor at the end of the Control.
To put the Cursor at the beginning…
Sub sMoveCursorToStart() On Error GoTo ClearIt 'Moves the cursor to the START of text in the control Dim ctl As Control Set ctl = Screen.ActiveControl If IsNull(ctl) Then Exit Sub ctl.SelStart = 0 Exit Sub ClearIt: Err.Clear End Sub
To use place the below in the On_Enter of the Control…
Me!YourControlName.EnterKeyBehavior = True sMoveCursorToStart
To put the Cursor at the end…
Sub sMoveCursorToEnd() On Error GoTo ClearIt 'Moves the cursor to the END of text in the control Dim ctl As Control Set ctl = Screen.ActiveControl If IsNull(ctl) Then Exit Sub ctl.SelStart = Len(ctl.Text) Exit Sub ClearIt: Err.Clear End Sub
To use place the below in the On_Enter of the Control…
Me!YourControlName.EnterKeyBehavior = True sMoveCursorToEnd
733 total views, 1 views today