Another question


Posted by J Tompson on August 14, 2001 7:30 AM

Hi,
Another question...

I have several textboxes and i want to make sure that they contain numbers rather than text. I know that i can make sure that the character is avalid one but i'm not surer how this is done. I also want to limit the number of characters to 2 per textox.

I don't want this to affect the whole userform but only a few select textboxes.

Thanks again,

John



Posted by Ryan on August 14, 2001 10:33 AM

In the textbox properties you can set "MAXLENGTH" value to "2." Also if you want to make sure the entered value is a number then you can enter an "Exit" sub like this:

Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If Not IsNumeric(TextBox1.Value) Then
MsgBox "Must be a number", vbOKOnly + vbCritical, "Error"
With TextBox1
.Value = ""
.SetFocus
End With
End If
End Sub