Ivan, can you please help me with this small problem!
Posted by Anna Daly on March 13, 2001 9:35 AM
Hi,
I have a small problem with data validtion in a textbox on a userform. I want to make it so that the user can only input numeric values into the textbox and that the values are then displayed in this fromat 1,000,000 etc.
This is the solution that I came up with:
Function CheckNum(TB As control)
If Not ((IsNumeric(TB.Value)) Or (TB.Value = "")) Then
MsgBox "This field only accepts numeric values!", vbCritical
CheckNum = False
TB.Value = ""
Else
CheckNum = True
TB.Value = Format(TB.Value, "#,##0")
End If
End Function
However, this does not allow the user to input decimal points. I would like to make it so that the user can put decimal numbers like 2345.75 into the textbox. The textbox would then display that number as 2,345.75 However, if the user does not use a decimal point then the umber is displayed only as an integer ie if the user eneters 2345 it is displayed in the textbox as 2,345 Any ideas how this can be done? I think that I am nearly there with the code shown above, I just don't know how to adapt it for decimal numbers.
Thank you kindley for your help,
regards
Anna