![]() |
|
#1
|
|||
|
|||
|
I have a textbox on a userform that I am trying to restrict user input to only allow integer values. I am able to do this, but the behavior is a little weird. First, here is my code:
Code:
Private Sub txtAnswer_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
If (KeyAscii >= 48) And (KeyAscii <= 57) Then
Me.txtAnswer.SetFocus
Else
KeyAscii = 0
Me.txtAnswer.SetFocus
End If
End Sub
All I want to do is make sure that the user doesn't enter something like "r" (or any other non-integer value) in the textbox. Any integer value >= 0 is perfectly acceptable (including multiple digit values like 10 or 1000000). Can anybody see why my approach isn't working? I've tried a few different approaches and have searched around quite a bit, but I can't find something that works. Thank you.
|
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
Restricting paragraph styles without restricting character styles
|
Red Pill | Word | 5 | 05-25-2012 01:06 PM |
Display result in textbox based on the input of another textbox
|
scarymovie | Word VBA | 5 | 05-16-2012 07:05 PM |
Setting focus to specific word document from UserForm
|
SaneMan | Word VBA | 5 | 04-01-2011 03:11 PM |
| Look up an array based on user input | johnsmb | Excel | 2 | 01-07-2011 01:12 PM |
| restricting template changes | ljfergus | Word | 0 | 04-13-2010 03:19 AM |