Page 1 of 2 12 LastLast
Results 1 to 15 of 21
  1. #1
    Join Date
    Sep 2003
    Location
    MI
    Posts
    3,713

    Unanswered: The lovely KeyDown event ... Access 2000

    Hi all.

    You're <insert adjective here> former Grand Poobah here with a question on the KeyDown event ... I have a series of single digit textboxes (in a row) that is used for typing in an account #. What I'd like to do is to have the interface automatically move to the next textbox in line upon entry of a number or letter into each textbox. My thoughts are to use the KeyDown event to do this ... Any thoughts on the KeyCode comparison to restrict this movement to only [A ... Z], [a ... z] and [0 ... 9]?

    Thanks once again.

    - Mike

    Code:
    Private Sub Digit1Txt_KeyDown(KeyCode As Integer, Shift As Integer)
        On Error Resume Next
        
        If KeyCode Then Digit2Txt.SetFocus
    End Sub
    Back to Access ... ADO is not the way to go for speed ...

  2. #2
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    just to be difficult, i'm going to suggest an input mask of
    A;;_

    izy
    currently using SS 2008R2

  3. #3
    Join Date
    Sep 2003
    Location
    MI
    Posts
    3,713
    I kinda figured on that (the mask AND you being difficult)... That restricts to 1 character, now I gotta work on automatically moving to the next control ...
    Back to Access ... ADO is not the way to go for speed ...

  4. #4
    Join Date
    Sep 2003
    Location
    MI
    Posts
    3,713
    This might work:
    Code:
        Select Case Chr(CLng(KeyCode))
            Case "A" To "Z", "a" To "z", "0" To "9"
                Digit2Txt.SetFocus
            Case Else
        End Select
    Back to Access ... ADO is not the way to go for speed ...

  5. #5
    Join Date
    Sep 2003
    Location
    MI
    Posts
    3,713
    It does ... Kinda. It moves me to the next control BUT (and I mean BUT) it does not display the typed character ...

    Any ideas???
    Back to Access ... ADO is not the way to go for speed ...

  6. #6
    Join Date
    Feb 2004
    Location
    Chicago, IL
    Posts
    1,312
    I would suggest using the KeyPress event. You might also think about the SendKeys function. That way you don't have to worry about changing the order of the textboxes. Anyway this is what I came up with for three text boxes:

    Code:
    Public Function ValidKey(intKey As Integer) As Boolean
        
        Select Case intKey
        
            Case 48 To 57, 65 To 90, 97 To 122
                ValidKey = True
            Case Else
                ValidKey = False
            
        End Select
        
    End Function
    
    Private Sub txt1_KeyPress(KeyAscii As Integer)
    
        If ValidKey(KeyAscii) Then
        
            SendKeys "{TAB}"
            
        End If
    
    End Sub
    
    Private Sub txt2_KeyPress(KeyAscii As Integer)
    
        If ValidKey(KeyAscii) Then
        
            SendKeys "{TAB}"
            
        End If
    
    End Sub
    
    Private Sub txt3_KeyPress(KeyAscii As Integer)
    
        If ValidKey(KeyAscii) Then
        
            SendKeys "{TAB}"
            
        End If
    
    End Sub

  7. #7
    Join Date
    Sep 2003
    Location
    MI
    Posts
    3,713
    Quote Originally Posted by DCKunkle
    I would suggest using the KeyPress event. You might also think about the SendKeys function. That way you don't have to worry about changing the order of the textboxes. Anyway this is what I came up with for three text boxes:

    Code:
    Public Function ValidKey(intKey As Integer) As Boolean
        
        Select Case intKey
        
            Case 48 To 57, 65 To 90, 97 To 122
                ValidKey = True
            Case Else
                ValidKey = False
            
        End Select
        
    End Function
    
    Private Sub txt1_KeyPress(KeyAscii As Integer)
    
        If ValidKey(KeyAscii) Then
        
            SendKeys "{TAB}"
            
        End If
    
    End Sub
    
    Private Sub txt2_KeyPress(KeyAscii As Integer)
    
        If ValidKey(KeyAscii) Then
        
            SendKeys "{TAB}"
            
        End If
    
    End Sub
    
    Private Sub txt3_KeyPress(KeyAscii As Integer)
    
        If ValidKey(KeyAscii) Then
        
            SendKeys "{TAB}"
            
        End If
    
    End Sub
    Thanks for the idea ... I fine tuned mine. This works pretty good:
    Code:
    Private Sub Digit2Txt_KeyDown(KeyCode As Integer, Shift As Integer)
        On Error Resume Next
        
        Select Case Chr(CLng(KeyCode))
            Case "A" To "Z", "a" To "z", "0" To "9"
                Digit2Txt.Value = Chr(CLng(KeyCode))
                Digit3Txt.SetFocus
            Case Else
        End Select
    End Sub
    Back to Access ... ADO is not the way to go for speed ...

  8. #8
    Join Date
    Nov 2004
    Location
    Norway
    Posts
    441
    It is kind of working, but that's just because you haven't cancelled the keystroke (what happens if you press the 0 key on the numeric keyboard?)

    What happens here, is that you receive a keycode, tesit it, and if it validates, then the keycode is assigned to the control - in a SELECTED state - so that when when the keycode is entered in the control, it replaces the character you've inserted.

    For the fun of it, cancel the keystroke within the routine (keycode = 0), then pay attention to what happens if you use the numeric keyboard, not the numbers on the top of the keyboard.
    Roy-Vidar

  9. #9
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    try my input mask
    ...and in the _Change()
    nextBox.setfocus

    im pecc able


    izy
    currently using SS 2008R2

  10. #10
    Join Date
    Sep 2003
    Location
    MI
    Posts
    3,713
    Quote Originally Posted by RoyVidar
    It is kind of working, but that's just because you haven't cancelled the keystroke (what happens if you press the 0 key on the numeric keyboard?)

    What happens here, is that you receive a keycode, tesit it, and if it validates, then the keycode is assigned to the control - in a SELECTED state - so that when when the keycode is entered in the control, it replaces the character you've inserted.

    For the fun of it, cancel the keystroke within the routine (keycode = 0), then pay attention to what happens if you use the numeric keyboard, not the numbers on the top of the keyboard.
    Ok Roy, You got my attention ... Numeric keypad blows with my routine ... Now, how to fix? ... Something to do with the Shift code ... Hmmmm ...
    Back to Access ... ADO is not the way to go for speed ...

  11. #11
    Join Date
    Sep 2003
    Location
    MI
    Posts
    3,713
    Quote Originally Posted by izyrider
    try my input mask
    ...and in the _Change()
    nextBox.setfocus

    im pecc able


    izy
    ... and here I was just starting to have fun ...
    Back to Access ... ADO is not the way to go for speed ...

  12. #12
    Join Date
    Nov 2004
    Location
    Norway
    Posts
    441
    Hm - I can't make my keydown event give another control focus, but that's probably another story, try:

    select case keycode
    case vbkeya to vbkeyz, vbkey0 to vbkey9, vbkeynumpad0 to vbkeynumpad9
    ' other code
    case else
    keycode =0
    end select
    Roy-Vidar

  13. #13
    Join Date
    Sep 2003
    Location
    MI
    Posts
    3,713
    Quote Originally Posted by RoyVidar
    Hm - I can't make my keydown event give another control focus, but that's probably another story, try:

    select case keycode
    case vbkeya to vbkeyz, vbkey0 to vbkey9, vbkeynumpad0 to vbkeynumpad9
    ' other code
    case else
    keycode =0
    end select
    I can ... I did. I was (just looking at your list) missing the numpad values ...
    Back to Access ... ADO is not the way to go for speed ...

  14. #14
    Join Date
    Sep 2003
    Location
    MI
    Posts
    3,713
    Quote Originally Posted by izyrider
    try my input mask
    ...and in the _Change()
    nextBox.setfocus

    im pecc able


    izy
    Once again ... Izy to the rescue ... Nice and simple. No complications. Thanks Izy!
    Back to Access ... ADO is not the way to go for speed ...

  15. #15
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    $#1t - i forgot to insert the adjective
    currently using SS 2008R2

Posting Permissions

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