databasedev.co.uk - database solutions and downloads for microsoft access

Microsoft Access Form Behaviors

Moving the Cursor To The End Of A Microsoft Access Textbox:

In Microsoft Access, you can specify the location of the insertion point when pressing the ENTER, TAB, or arrow keys to move from field to field on forms and datasheets. From the Tools menu, click Options, and then click the Keyboard tab:

  1. Under Arrow key behavior, click Next field.
  2. Under Behavior entering field, do one of the following: To select the entire field when you enter it, click Select entire field.

    To place the insertion point at the start of the field when you enter it, click Go to start of field.

    To place the insertion point at the end of the field when you enter it, click Go to end of field.

Sometimes, however, you may not need to specify these behaviors as default, and may only want to apply settings for single form fields. You may have a memo field where you want the cursor insertion point to always go to the end of the text box.

To automatically place the cursor at the end of the text that is already there we need to use the SelStart property of the control.

If we look at the following example, after tabbing into the Notes field, the whole text is selected. This is due to the default behavior that is currently set (Select entire field):

Default cursor selection, selecting the whole textbox
Default cursor selection, selecting the whole textbox

Using the following code, place in the OnEnter event of the control on our form ensures that when the control is activated, the cursor will automatically be placed at the end of all the text present in the textbox:

Private Sub memPropertyNotes_Enter()
    Me!memPropertyNotes.SelStart = Me!memPropertyNotes.SelLength
End Sub

Now, when we tab into the textbox, the cursor is automatically placed at the end of any text that is already present:

The cursor now defaults to the end of any text that is already present in the textbox, when we tab into the field.
The cursor now defaults to the end of any text that is already present in the textbox, as shown above, when we tab into the field.