Hi! I would like to share what I have created. It just a simple could that will limit the textbox entry to numbers only.
The code is in a module so you can reuse it. BTW, it also allows you to use period(.) and negative(-). You are limited to use only one negative sign and can only be put before any number.
I have not included enter key in the module instead it is done in the keypress event of textbox.
Please leave me some reputation if you like this code!
Code edited: Now right click and paste is disabled
Last edited by Simply Me; May 28th, 2006 at 08:40 AM.
Reason: Right Click and Paste added
To give is always to be NOBLE...
To received is always to be BLESSED....
Each day strive to be NOBLE
Each day strive to be BLESSED
If this post has helped you. Please take time to rate it.
There's still a problem with your code. You used MouseDown event to disable right mouse click. So. Click on any TextBox with right mouse button and hold it, then press ENTER to supress the MsgBox, and release mouse button you're holding
'Call the function Ut_IntegerValidation on any textbox or control which has .text property
Private Sub Text1_Change()
Ut_IntegerValidation Text1
End Sub
'Paste the following code in a module
Public Function Ut_IntegerValidation(ByVal MyTextBox As Control)
If Not IsNumeric(MyTextBox.Text) Then
MyTextBox.Text = ""
ElseIf IsNumeric(MyTextBox.Text) Then
If Val(MyTextBox.Text) < 0 Then
MyTextBox.Text = ""
End If
End If