Click to See Complete Forum and Search --> : Filter Input to Textbox Within an ActiveX Control


Scott Johnston
January 12th, 2000, 04:45 AM
I have a Textbox control within an ActiveX Control. I wish any input to the textbox to be numeric only. A decimal point is permitted but only once. The following code is included in my Textbox keypress event:

Private Sub txtValue_KeyPress(KeyAscii As Integer)

'Allow the backspace key to pass through but only allow the
'decimal point key to pass through if it isn't in the string already...
If KeyAscii = 46 And InStr(txtValue.Text, ".") = 0 Or KeyAscii = 8 Then
Exit Sub
'Only update if the Enter Key is Pressed...
Else
'Only let number keys through...
If KeyAscii < 48 Or KeyAscii > 57 Then
'MsgBox "Numeric Input Only...!", vbOKOnly, "Numeric Input Error"
KeyAscii = 0
End If
End If

End Sub

This code appears to work fine in a textbox on its own. Problem is it gives bizarre results and does not accept a decimal point when included in my control!!!

Any pointers would be much appreciated...

Chris Eastwood
January 13th, 2000, 03:17 AM
I've just tried your code on a simple usercontrol (ie. one text box called txtValue) and put it into a simple project.

It all worked fine ! - Maybe something else is wrong in your UserControl / Sample Project

Chris Eastwood

CodeGuru - the website for developers
http://codeguru.developer.com/vb

Scott Johnston
January 13th, 2000, 03:46 PM
Oops, My mistake... you were correct Chris

I replied to you through a private message describing my problem.

Thanks for taking the time to look at my problem!!