|
-
Nov 15th, 2000, 02:12 PM
#1
Thread Starter
Addicted Member
Any one know the easiest way to only allow numbers into a text box, I saw a reply to someone elses post a few weeks ago but didn't bother to note it, it was only about 1 line of code.
Thanks in advance!!!
-
Nov 15th, 2000, 02:27 PM
#2
here is one way....
Code:
Private Sub Text1_KeyPress(KeyAscii As Integer)
Select Case KeyAscii
Case 8
' Backspace OK.
Case 13
' Enter treated like Tab.
Text2.SetFocus
Case 48 To 57
' numbers only
Case Else
' Reject all else.
KeyAscii = 0
End Select
End Sub
-
Nov 15th, 2000, 02:30 PM
#3
Thread Starter
Addicted Member
I did one similar to that Larryn but using the vbconstants and it didn't work?
But I'll give your code a go...Thanks!!!
-
Nov 15th, 2000, 02:38 PM
#4
Thread Starter
Addicted Member
I solved my one and tried yours Larryn. Thanks for your help!!!
-
Nov 15th, 2000, 02:45 PM
#5
_______
Code:
'allow only numeric data in a textbox
Option Explicit
Private Sub Text1_KeyPress(KeyAscii As Integer)
If Not IsNumeric(Chr(KeyAscii)) Then KeyAscii = 0
End Sub
[Edited by HeSaidJoe on 11-15-2000 at 03:45 PM]
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
Nov 15th, 2000, 03:27 PM
#6
Actually, you should set the KeyAscii to 0 rather than 13.
Code:
Private Sub Text1_KeyPress(KeyAscii As Integer)
If Not IsNumeric(Chr(KeyAscii)) Then KeyAscii = 0
End Sub
-
Nov 15th, 2000, 03:43 PM
#7
_______
<?>
duh..I knew that...it's those cheap drugs....ran out.LOL..
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
Nov 15th, 2000, 05:54 PM
#8
Hyperactive Member
larryn, instead of calling text2.setfocus, you should use SendKeys "{TAB}". That way, you won't have to keep updating the code if you change text2's name or tab order.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|