Results 1 to 5 of 5
  1. #1
    Bazsl is offline Advanced Beginner
    Windows 10 Access 2013 64bit
    Join Date
    Jun 2016
    Posts
    47

    How position cursor at the beginning of a textbox that has an edit mask?

    I am new to Access. If I click the mouse in an empty bound TextBox that has an input mask the cursor will be left on the character position in the input mask that I happened to click. How can I automatically position the cursor on the first character of the input mask? I assume I can do this in either the OnEnter or OnGotFocus event handler but I am not sure which event to use or how to position the cursor at the left-most character of the mask. Thanks.

  2. #2
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,441
    I use this function to go to the last character in the field you can adapt it to your situation

    Code:
    Public Function PFLP()
    'moves cursor to the last position of any field, used to prevent accidental overwriting of data
    'SYNTAX:  PFLP
    On Error GoTo ERRHANDLER
    If Screen.ActiveControl.Enabled = True Then
        If InStr(Screen.ActiveControl.Tag, "ED") > 0 Then       'ED in the string indicates a date value
            If IsNull(Screen.ActiveControl.Value) Then          'Empty Date
                Screen.ActiveControl.SelStart = Screen.ActiveForm(Screen.ActiveControl.Name & "").SelLength
            Else                                                'Date present with \ marks
                Screen.ActiveControl.SelStart = Screen.ActiveForm(Screen.ActiveControl.Name & "").SelLength + 2
            End If
        Else                                                    'other text or numeric field
            Screen.ActiveControl.SelStart = Screen.ActiveForm(Screen.ActiveControl.Name & "").SelLength
        End If
    End If
    Exit Function
    ERRHANDLER:
    Resume Next
    End Function
    it may be as simple as screen.activecontrol.selstart = 0 or screen.activecontrol.selstart = 1. I'm unsure how input masks may affect this. All you'd have to do is put in the ON ENTER property of the field pflp and possible in the ON CLICK event of the field as well.

  3. #3
    Bazsl is offline Advanced Beginner
    Windows 10 Access 2013 64bit
    Join Date
    Jun 2016
    Posts
    47
    I must be missing something. I have tried calling the following from both OnEnter and GotFocus.

    Private Sub MoveCursorToFirstChar()
    If IsNull(Screen.ActiveControl.Value) Then
    Screen.ActiveControl.SelStart = 0
    End If
    End Sub

    I have stepped through the code in the debugger and SelStart = 0 does execute but the cursor does not move to the first position in the input mask. The input mask is 000\-000\-0000. Any idea why this does not work? Thanks.

  4. #4
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,441
    I posted what I use because it specifically handles dates where the / marks are part the input mask use the ON CLICK event of the field as well

  5. #5
    Bazsl is offline Advanced Beginner
    Windows 10 Access 2013 64bit
    Join Date
    Jun 2016
    Posts
    47
    OnClick did the trick. Sorry I missed that in your original post. Many thanks.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 04-29-2016, 09:06 PM
  2. Replies: 2
    Last Post: 01-04-2016, 04:44 AM
  3. Replies: 9
    Last Post: 09-02-2014, 10:56 AM
  4. Replies: 6
    Last Post: 12-05-2013, 09:55 AM
  5. Bold Field by Cursor Position
    By Rawb in forum Forms
    Replies: 4
    Last Post: 02-08-2011, 08:03 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums