Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Comma's in the wrong place still recognized as numbers in textbox

Status
Not open for further replies.

senators40

Technical User
Jan 7, 2003
68
CA
Hi,

I have a textbox in a userform. I have used the following commands to tell people to enter numbers only. Unfortunately if the user were to enter 50,00 (misplacing the comma) the vb code will still think this is a number and cause an error in the further code (adding the numbers into a final textbox (ie textbox1 + textbox2 = textbox3).

This also seems to have a problem with $ and + , at the beginning and end of the numbers as well.

The following is the code that I am using.

'To make sure that the person enters a number
If TextBox1 = vbNullString Then Exit Sub
If Not IsNumeric(TextBox1) Then
MsgBox "Sorry, numbers only"
TextBox1 = vbNullString
End If

Does anyone have any suggestions.

Also acceptable would be to remove the comma's automatically if the user enters them into the textbox

Thanks

Jeff
senators40@hotmail.com
 
Jeff,

without going deeply into this, how about using Val(textbox). This forces a number. I am not sure what it does with commas. It may even handle them as you wish.

Rollie E
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top