T
thesteelmaker
The code at the bottom gives me a textbox, formatted to 1 dp. Som
vailidation to stop "text" enteries and some validation to give
positive number.
All is ok so far.
On doing some testing, the text box lets me do some strange things
that i do not want, i.e.:
Enter into text box
6.6.6 this changes to 0.3
6 7 changes to 38174.0
5/8/0 changes to 36743.0
I take it the last two are accepted as dates.
why?
These are errors that i dont really want.
Any suggestions would be helpful.
Thanks
Code=================================
Private Sub TextBox1_BeforeUpdate(ByVal Cancel A
MSForms.ReturnBoolean)
' Set number format
TextBox1.Text = Format$(frmTest.TextBox1.Text, "####0.0")
' Check the value entered is numeric
If Not IsNumeric(TextBox1.Value) Then
MsgBox "You entered a non-numeric value, try again."
vbExclamation, "Error"
TextBox1.SetFocus
TextBox1.SelStart = 0
TextBox1.SelLength = Len(TextBox1.Text)
Cancel = True
Else
' Check the value is positive
If (TextBox1.Text < 0) Then
MsgBox "You inserted a negative number, try again."
vbExclamation, "Error"
TextBox1.SetFocus
TextBox1.SelStart = 0
TextBox1.SelLength = Len(TextBox1.Text)
Cancel = True
End If
End If
End Sub
Private Sub UserForm_Initialize()
TextBox1.Text = ""
TextBox2.Text = ""
TextBox1.SetFocus
End Su
vailidation to stop "text" enteries and some validation to give
positive number.
All is ok so far.
On doing some testing, the text box lets me do some strange things
that i do not want, i.e.:
Enter into text box
6.6.6 this changes to 0.3
6 7 changes to 38174.0
5/8/0 changes to 36743.0
I take it the last two are accepted as dates.
why?
These are errors that i dont really want.
Any suggestions would be helpful.
Thanks
Code=================================
Private Sub TextBox1_BeforeUpdate(ByVal Cancel A
MSForms.ReturnBoolean)
' Set number format
TextBox1.Text = Format$(frmTest.TextBox1.Text, "####0.0")
' Check the value entered is numeric
If Not IsNumeric(TextBox1.Value) Then
MsgBox "You entered a non-numeric value, try again."
vbExclamation, "Error"
TextBox1.SetFocus
TextBox1.SelStart = 0
TextBox1.SelLength = Len(TextBox1.Text)
Cancel = True
Else
' Check the value is positive
If (TextBox1.Text < 0) Then
MsgBox "You inserted a negative number, try again."
vbExclamation, "Error"
TextBox1.SetFocus
TextBox1.SelStart = 0
TextBox1.SelLength = Len(TextBox1.Text)
Cancel = True
End If
End If
End Sub
Private Sub UserForm_Initialize()
TextBox1.Text = ""
TextBox2.Text = ""
TextBox1.SetFocus
End Su