troubleshooting Question

How to restrict a VBA text box to accept letters only

Avatar of FaheemAhmadGul
FaheemAhmadGulFlag for United Kingdom of Great Britain and Northern Ireland asked on
Microsoft OfficeMicrosoft AccessMicrosoft ExcelMicrosoft WordVBA
6 Comments2 Solutions169 ViewsLast Modified:
I have textBox on a VBA form named txtAnswer

I would like to restrict what can be entered in a VBA TextBox (txtAnswer) to letters only.
If the user presses a number key the number will not be typed into the TextBox but instead a Message Box will pop up showing the number key that has been pressed. Also if the user presses the Enter Key a Message Box should pop up saying “You pressed Enter Key”

So if the user starts typing “ a p p p l e  “ then the word “apple” will get typed into txtAnswer, but if the user presses a number key such 3 then the text in the txtAnswer will remain unchanged but a message box will pop saying “You pressed 3 ‘“
Thank you for your help.
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 2 Answers and 6 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 6 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros