test keycode for alphanumeric character


i have a keydown event and only want to run if an alphanumeric character is pressed. i think this is a UDF requirement.

how would yall design it? if yall could share even some air code that would be great!!

i'm so so sorry i'm so super overloaded now!!

i'm thinking something like convert the keycode to alpha and then test it for >=A <=z and also for numbers. can't think of the exact implementation but something along those lines! thanks guys!! = ))
Who is Participating?
als315Connect With a Mentor Commented:
Alphanumeric characters are in some range in ascii table:
Keycode 48-57 : numbers from 0 to 9
65-90 : A-Z
97-122 : a-z
so you can check code without conversion:
If keycode >47 and keycode < 58 then 'numeric
Anthony BerenguelCommented:
Here's an example I have used before -- you will need to modify the selection statement to fit your needs.

Private Sub cbxControl_ID_KeyPress(KeyAscii As Integer)
    Debug.Print KeyAscii
    If KeyAscii = 27 Then 'esc key
        Me.cbxControl_ID.Width = 1440
    End If
End Sub

Open in new window

developingprogrammerAuthor Commented:
great! thanks aebea and als315!! = ))
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.