Share via

MS Access cursor position

Anonymous
2023-02-03T03:30:13+00:00

I need for the cursor to land in the first position when you click on a field. Right now it lands wherever you click within the field. Not optimal for data entry.

Thanks for the help!

Microsoft 365 and Office | Access | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

14 answers

Sort by: Most helpful
  1. Anonymous
    2023-02-03T04:08:47+00:00

    Hello

    I am Abdal and I would be glad to help you with your question.

    To change the cursor position in Microsoft Access, you can use the "SetFocus" method in the VBA code. Here's an example:

    Private Sub Form_Current() Me.txtFieldName.SetFocus Me.txtFieldName.SelStart = 0 End Sub

    In this example, the cursor will be placed in the first position of the "txtFieldName" field every time you navigate to a new record in the form.

    I hope this information helps.

    Regards,

    Abdal

    Was this answer helpful?

    1 person found this answer helpful.
    0 comments No comments
  2. George Hepworth 22,855 Reputation points Volunteer Moderator
    2023-02-03T15:35:28+00:00

    Did you actually try your suggestion yet?

    And, keep in mind, the OP is asking for this to be done on any control on the form, not just the single hard-coded control in your response.

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2023-02-03T15:27:40+00:00

    Hello

    The solution I provided works for all types of fields, including date and fields with an input mask. However, if you're clicking on a field that is not the first field, the cursor may not always be placed at the first position.

    One solution to this is to use the "SetFocus" method in combination with the "SelStart" property every time you edit a field in the form. You can do this by creating a custom event for the form or for each individual field.

    Here's an example of how to do this for a form:

    Private Sub Form_BeforeUpdate(Cancel As Integer) Me.txtFieldName.SetFocus Me.txtFieldName.SelStart = 0 End Sub

    In this example, the "Form_BeforeUpdate" event is triggered before any changes are made to the form. When this event is triggered, the cursor will be placed at the first position of the "txtFieldName" field.

    You can also create similar custom events for each individual field by using the "GotFocus" event. This way, the cursor will be placed at the first position whenever the focus is set to a specific field.

    Regards,

    Abdal

    Was this answer helpful?

    0 comments No comments
  4. George Hepworth 22,855 Reputation points Volunteer Moderator
    2023-02-03T15:10:53+00:00

    No, that code would only work for the control specified, and only when the record was first made current. It wouldn't even fire when you clicked on a different control with the mouse.

    However, I've been trying to make this work with the GotFocus or OnEnter events of controls, so far with no success. I'm a bit puzzled as the documentations suggests it should. Sorry, I should have posted an interim response; I wanted to try to resolve the approach first. The .SelStart method is supposed to do what you want, but it appears only to work at the record level and that behavior is at odds with what I remembered. Don't give up, but please give us some time to see what's up.

    Was this answer helpful?

    0 comments No comments
  5. Anonymous
    2023-02-03T14:38:50+00:00

    When I edit a field I often click on a field within the form that is not the first field. Many of those fields are date fields or fields with an Input Mask. How do I get it so the cursor goes to the first position of a field? Is the solution you propose supposed to work on all fields?

    Thanks.

    Was this answer helpful?

    0 comments No comments