Text box for numbers only.

  • Thread starter Thread starter Shotodru
  • Start date Start date
S

Shotodru

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
 
From Shotodru :
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

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top