View Full Version : [SOLVED:] Blocking Alphabetical Entries into Textboxes
Shrout1
10-05-2004, 12:42 PM
There is an error on my form when a user makes an alphabetical entry into one of the text fields. I have it set to automatically run a calculation subroutine when all the required fields are filled in and so this is giving me grief.
Any help would be greatly appreciated! Thanks!
Zack Barresse
10-05-2004, 01:48 PM
Hello Shrout,
Do you mean UserForm? If so, are you using a TextBox? Is the action from a CommandButton? If so, what is your CommandButton code and name of all objects in this association?
Shrout1
10-05-2004, 01:55 PM
Yes - I'm using a userform and a textbox.
It isn't tied to a command button, it's tied to a textbox_Change routine. Basically, the value that is typed into the textbox is stored as a variable and then a sub is called up that checks if the other textboxes are filled.
If the others have values then the program starts doing math - something that letters will mess up :-p. I was hoping there was an easy way to lock a textbox from letters, but I've never heard of one...
mdmackillop
10-05-2004, 02:03 PM
Do a check as the numbers/text is entered
MD
eg
Private Sub TextBox1_Change()
If Not IsNumeric(TextBox1) Then MsgBox "Numbers Only"
End Sub
Jacob Hilderbrand
10-05-2004, 02:18 PM
This will only allow numbers 0-9:
Private Sub TextBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
If KeyAscii < 48 Or KeyAscii > 57 Then
KeyAscii = 0
Beep
End If
End Sub
This will allow one decimal:
Private Sub TextBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
Dim x As Integer
Dim y As String
If KeyAscii < 46 Or KeyAscii > 57 Or KeyAscii = 47 Then
KeyAscii = 0
Beep
End If
If KeyAscii = 46 Then
y = TextBox1.Text
For x = 1 To Len(y)
If Mid(y, x, 1) = "." Then KeyAscii = 0
Next x
End If
End Sub
Shrout1
10-08-2004, 08:33 AM
Thanks! I'll give this a try
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.