Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 346
  • Last Modified:

Access Alphabetical Characters Keypress

Working on function that only allows characters & backspace keystrokes in text box.

I'm calling function on keypress event

KeyAscii = CLimitTextInput(KeyAscii)   'Calling CLimitTextInput function.

When I test function, I do receive the error message if a numeric value is pressed, but when I type a character it does not appear in text box.  

 
 
Function CLimitTextInput(KeyAscii) As Integer
      Select Case KeyAscii
        ' 65 To 90 and 97 To 122: These are all alphas, upper and lowercase
        ' 8 Backspace, 9 Tab Key, 32 Space Key
    Case 65 To 90, 97 To 122, 8, 9, 32
    Case Else
        'Setting KeyAscii to zero cancels the key input
        KeyAscii = 0
        MsgBox ("Only Alphabetical Characters Allowed")
        Exit Function
    End Select
   End Function

Open in new window

0
jbakerstull
Asked:
jbakerstull
1 Solution
 
Jim Dettman (Microsoft MVP/ EE MVE)PresidentCommented:

You function needs to look like this:

Function CLimitTextInput(KeyAscii) As Integer
      Select Case KeyAscii
        ' 65 To 90 and 97 To 122: These are all alphas, upper and lowercase
        ' 8 Backspace, 9 Tab Key, 32 Space Key
    Case 65 To 90, 97 To 122, 8, 9, 32
    Case Else
        'Setting KeyAscii to zero cancels the key input
        KeyAscii = 0
        MsgBox ("Only Alphabetical Characters Allowed")
    End Select

   CLimitTextInput = KeyAscii

   End Function

JimD.
0
 
jbakerstullAuthor Commented:
Thank you.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now