Results 1 to 3 of 3
  1. #1
    4 Star Lounger
    Join Date
    Feb 2008
    Location
    United Kingdom
    Posts
    490
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Keycode Trap (MS ACCESS 2003)

    I am trying to prevent characters being entered in a textbox that are not Alphanumeric, except for a hyphen. Can someone tell me why the code below does not work properly, it's showing a message box every time. Thanks

    Private Sub IPA_KeyDown(KeyCode As Integer, Shift As Integer)


    Select Case KeyCode

    Case 65 - 90
    Exit Sub

    Case 97 - 122
    Exit Sub

    Case 45
    Exit Sub

    Case Else

    MsgBox "WRONG"
    KeyCode = 0 'disable key and/or combination
    End Select

    End Sub

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

    Re: Keycode Trap (MS ACCESS 2003)

    Instead of using

    Case 65 - 90

    which is evaluated as

    Case -25

    use

    Case 65 To 90

    and similar for the other one.

  3. #3
    4 Star Lounger
    Join Date
    Feb 2008
    Location
    United Kingdom
    Posts
    490
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Keycode Trap (MS ACCESS 2003)

    Aha, thank you Hans. trust your well, and many thanks again. Lost an hour trying to figure that one out.

Posting Permissions

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