Results 1 to 4 of 4

Thread: Key Ascii (2k)

  1. #1
    5 Star Lounger
    Join Date
    Jul 2004
    Location
    Ohio
    Posts
    629
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Key Ascii (2k)

    <P ID="edit" class=small>(Edited by officespacer on 02-Dec-04 15:25. Fixed some colors)</P>Hi, I'm trying to do something pretty simple but just not sure exactly how to go about what i'm trying to accomplish. On my form, I have many text boxes. Some of the text boxes are in the header so they can act similar to excel's freeze panes action does, allowing you to see everything else while keeping main info static on the window. The form loads and sets focus to the first tab stop in the header, and from there you can enter your data and tab through the text fields. After you finish on the header, you want to go into the body section and enter data there.

    SO, my problem is I want to move to the body section after the user presses TAB on the last text box in the header. My 2 problems are this: I don't know the ascii code for TAB, i think its 9 but i'm not positive, maybe thats my problem. 2nd problem: i'm not quite sure how to work it out so that it moves after you have initially tabbed into it. Heres the code I came up with.

    Public tabmover as Integer <font color=448800>'Tabmover is set to = 0 in form_load</font color=448800>
    Private Sub Text300_KeyPress(KeyAscii As Integer) <font color=448800>'Header text box</font color=448800>

    If KeyAscii = 9 Then
    tabmover = tabmover + 1 <font color=448800> 'to account for inital tab into the textbox </font color=448800>
    If tabmover = 2 Then <font color=448800>'when you are ready to tab out of the textbox</font color=448800>
    Combo147.SetFocus <font color=448800>'Body Combobox</font color=448800>
    tabmover = 0 <font color=448800>'reset incase they decide to re-tab through it all</font color=448800>
    End If
    End If

    End Sub

    So what happens here is the first time I tab into the control, the keypress is recorded (tabmover = 1). When i'm ready to tab out of the control however, the 2nd keystroke isn't counted under keypress for this control anymore (atleast I don't think it is), and it tab's to another control in the heading instead of going to the body controls. I know tab is counted when you tab into the control because my first code was just:

    If KeyAscii = 9 Then
    Combo147.SetFocus
    End If

    and it went to combo147 (which is good, but not what i want). any ideas on how to go about this? let me know if i'm not being clear enough.
    <img src=/w3timages/blueline.gif width=33% height=2>
    <big>John</big>

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Key Ascii (2k)

    Tab is ASCII code 9 indeed. I would use the On Key Down event instead of the On Key Press event. This occurs when the user depresses the tab (or any other) key in the Text300 text box. You can also check if the user held the Shift key down (Shift+Tab = back to previous control)

    Private Sub Text300_KeyDown(KeyCode As Integer, Shift As Integer)
    If KeyCode = 9 And (Shift And acShiftMask) = 0 Then
    Me.Combo147.SetFocus
    End If
    End Sub

  3. #3
    5 Star Lounger
    Join Date
    Jul 2004
    Location
    Ohio
    Posts
    629
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Key Ascii (2k)

    Hans I beat you to it! i may have cheated though. this is what i ended up doing:

    i have 5 static text boxes that don't get tab indexes at all, so I just set it so one of those text boxes had the next tab index after my last data entry control. then i just put that super simple code in _KeyPress:

    if keyascii = 9 then
    control.setfocus
    end if

    however i'll probably consider using what you said anyway because of the shift+tab event that I didn't think of for my code. Thanks!
    <img src=/w3timages/blueline.gif width=33% height=2>
    <big>John</big>

  4. #4
    Super Moderator
    Join Date
    Aug 2001
    Location
    Evergreen, CO, USA
    Posts
    6,623
    Thanks
    3
    Thanked 60 Times in 60 Posts

    Re: Key Ascii (2k)

    It appears to me you may have a situation where a subform would serve you well. If you are putting repeated information into each record, your table normalization may not be optimal either. Just my <img src=/S/2cents.gif border=0 alt=2cents width=15 height=15>
    Wendell

Posting Permissions

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