I am creating an application using Visual Basic 2005 (similar to .net)that reads values from a set of fields in order to perform numerical calculations. My question is the following, how can I prevent users or at least display a messagebox whenever users enter characters other than numerical characters?
Thank you in advance
Put the following code in the KeyPress event of your textbox:
'The User Pressed Enter
If KeyAscii = 13 Then
'Do your processing code here
'The user pressed non numeric character. Cancel the entry.
ElseIf KeyAscii <> 8 And (KeyAscii < 48 Or KeyAscii > 57) Then
KeyAscii = 0
Download for FREE the ADO/DAO Data Controls that makes life EASIER developing database applications in: VB, FoxPro, Access, VC++, .NET etc... Navigate, Add New, Delete, Update, Search, Undo and Save your changes. Supports Disconnected Recordsets and Transactions!
Or try our Ask An Expert service to answer any of your questions!