Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Text box for numbers only.

0 views
Skip to first unread message

Shotodru

unread,
Sep 27, 2005, 5:26:14 AM9/27/05
to
Dear Friends,
I have a certain text box on a form. I want this text box to be used for
capturing only numbers from the user. Accordingly, I have set the format
property of this text box to General Number.

Although, this performs to my requirements, the message which is displayed
when any characters other than numerals are entered, is not to my liking as
this message typically is an Access generated message.

What I need is to restrict the user to entering only the following:
a. Numbers.
b. The decimal point.
c. The plus or the minus signs.

Any other characters which the user might enter should not be accepted
and/or even displayed in the text box at all.

Any help on this issue is highly solicited.

Yours sincerely,
Shotodru

Gijs Beukenoot

unread,
Sep 27, 2005, 7:24:57 AM9/27/05
to
From Shotodru :

Have a look at the keydown event, you can create code there to
accomplish that.
Something like :

Private Sub Tekst0_KeyDown(KeyCode As Integer, Shift As Integer)

Select Case Chr(KeyCode)
Case "0", "1", "2", "3", "4", "5", "6", "7", "8", "9"
Case "."
Case Else
KeyCode = 0 'Cancels the input
End Select

End Sub

And perhaps validate the whole input to see if it's numeric with the
IsNumeric function


0 new messages