Results 1 to 5 of 5
  1. #1
    4 Star Lounger
    Join Date
    Jan 2001
    Location
    Atlanta
    Posts
    568
    Thanks
    7
    Thanked 1 Time in 1 Post

    Keystroke to jump to certain field (97)

    I have a fairly long data entry form where I often need to skip over fields to a specific field. Is there a way I can assign a keystroke (say Alt-S) to this field and jump immediately to it within a form?

    Ronny
    Ronny Richardson

  2. #2
    Star Lounger
    Join Date
    Dec 2001
    Location
    Birmingham, Alabama USA
    Posts
    95
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Keystroke to jump to certain field (97)

    Here is one way to do this:

    First set the "Key Preview" property of the form to Yes (the default is No).

    Now place the following in the "On Key Down" event of the form:
    <pre>Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    Dim intAltDown As Integer
    intAltDown = (Shift And acAltMask) > 0

    Select Case KeyCode
    Case vbKeyS
    If intAltDown Then
    Me.YourControlName.SetFocus
    End If
    End Select

    End Sub</pre>

    "YourControlName" should be the name of the control you want to receive focus when the key combination is executed.
    You can add more Alt+Key combinations to the Case Select statement as needed to do what you ask.

    HTH
    RDH
    Ricky Hicks
    Microsoft MVP
    Birmingham, Alabama USA

  3. #3
    5 Star Lounger
    Join Date
    Jan 2001
    Location
    Vancouver, Br. Columbia, Canada
    Posts
    632
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Keystroke to jump to certain field (97)

    Change the label associated with the field -- e.g, &Label. The "L" will appear underlined on the form.

    Pressing Alt-L will jump to this field.
    --------------------------------------------------
    Jack MacDonald
    Vancouver, Canada

  4. #4
    Bronze Lounger
    Join Date
    Nov 2001
    Location
    Arlington, Virginia, USA
    Posts
    1,394
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Re: Keystroke to jump to certain field (97)

    You can use control labels to create accelerator keys that allow you to jump to control by entering ALT + underscored character. You create accelerator key by typing an ampersand (&) before character you want to use as an accelerator. Example: For field named "Address" for label caption type "&Address". Caption on form will appear as Address. When user enters ALT + A focus will move to Address field (ie, control such as textbox to which label is attached). Only tricky thing is you need to use unique accelerator keys for each control. If used for command button caption, when you enter ALT + underscored character the button's click event will take place. For example, in attached illustration, if you type ALT + X (for "EXIT" button) form will close. Sample form shows how each label has different letter as accelerator. This works with numerical characters too (if you run out of letters).

    HTH
    Attached Images Attached Images

  5. #5
    4 Star Lounger
    Join Date
    Jan 2001
    Location
    Atlanta
    Posts
    568
    Thanks
    7
    Thanked 1 Time in 1 Post

    Re: Keystroke to jump to certain field (97)

    Okay, that works, thanks. I had tried changing the name of the field containing the data, which did not work. Changing the caption worked.

    Ronny
    Ronny Richardson

Posting Permissions

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