Results 1 to 4 of 4
  1. #1
    Star Lounger
    Join Date
    Oct 2001
    Posts
    51
    Thanks
    0
    Thanked 0 Times in 0 Posts

    set focus to field (Access XP)

    <P ID="edit" class=small>Edited by scottburke on 23-Jul-02 14:47.</P>I forgot the syntax for setting focus to a field when opening a form. The field I would like to set focus to is "employee"

    I think its something like:

    Got it.
    Private Sub Form_Current()
    Me![Employee].SetFocus
    End Sub

    Any help would be much appreciated.
    Thank you.

  2. #2
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: set focus to field (Access XP)

    Try

    ME![EMPLOYEE].SETFOCUS

    Perhaps it would be better with the on Open event. With on current, when you try to move out of the field, the on current will (I think) try to pull the focus back to the focus'd field.

    Other alternatives are :-
    Private Sub Form_Open(Cancel As Integer)
    Forms!frmYourFormName!txtYourFieldName.setfocus
    End Sub

    In the past I have had to fully reference in steps

    forms!frmYourFormName.setfocus
    forms!frmYourFormName!txtYourFieldName.setfocus

    Dave

  3. #3
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: set focus to field (Access XP)

    You only have to fully reference the form if you're doing this from outside that particular form. The Me object includes the full reference to the form.
    Charlotte

  4. #4
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: set focus to field (Access XP)

    As Dave pointed out, the Current event is not the right one to use for this. For one thing, the current event fires several times when the form is being opened, and it fires when you move between records as well. Use the Open or Load events to set the focus. Your syntax should work just fine, assuming that Employee is the name of the control itself and not just the name of the field it's bound to.
    Charlotte

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •