numbers not text

M

Mazza

Hi all,
Can somebody tell me how to stop users entering text in a text box that
should only receive numbers. I have a very successful database that requires
the users to search for a client by entering their ID number or surname. The
surname search has proven to be a problem due to too many 'Smiths' etc. So I
want the users to use only the ID number. The idea is that if they start
typing text that a message pops up to inform them that only the ID number
will be accepted.
Thanks in advance to anyone that can help me with this problem.

M
 
D

Daveo

Hi,

Probably the easiest way is to use an input mask instead of any VBA.

With the form in design view, select the text box properties and find
the "Input Mask" property under the Data tab. If the ID number is
always the same length enter as many 0's (zeros) as applicable. If the
ID number can be different lengths, enter as many 9's as required. This
makes it impossible for a user to enter anything other than a number
into the next box.

Hope this helps,

David
 
G

Guest

Hi,
there are many different ways to achieve this.
One would be to use the keypress event of the control to check for the ASCII
codes of the used values e.g.:

Private Sub YourControl_KeyPress(KeyAscii As Integer)

If KeyAscii >= 48 And KeyAscii <= 57 Or KeyAscii = 8 Then
Else
KeyAscii = 0
End If

End Sub

This would only allow numbers and backspaces.
Another way would be to adjust the format property of the control to a
general number. Furthermore, you could also use the IsNumeric() function on
the after update event of the control. The difference between the first
method and the others would be when you want the user to be warned about the
invalid entries. The first one will not allow any entry right away. The
others would require the control to lose focus.
HTH
Good luck
 

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

Similar Threads


Top