Solved

Limit entries in text box

Posted on 2000-03-19
3
138 Views
Last Modified: 2010-05-02
A pretty dumb question really, but I am trying to limit text box entries to numbers only ?
I also need to allow the decimal point and backspace key to be used in the same text box ?
I can limit the entry to just numbers by using this line of code in the KeyPress event to display an error message if the user enters anything but the numbers 0 to 9.
If KeyAscii < Asc("0") Or KeyAscii > Asc("9") Then
Error message etc.

Help!
0
Comment
Question by:webstudio1
  • 2
3 Comments
 
LVL 14

Accepted Solution

by:
mcrider earned 100 total points
ID: 2633629
Here you go...

Private Sub Text1_KeyPress(KeyAscii As Integer)
    Select Case KeyAscii
        Case 8, 46, 48 To 57
            'DO NOTHING
        Case Else
            KeyAscii = 0
    End Select
End Sub


Cheers!®©
0
 

Author Comment

by:webstudio1
ID: 2633678
The obvious really hurts sometimes.
Thanks
Kenny
0
 
LVL 14

Expert Comment

by:mcrider
ID: 2633896
No such thing as a dumb question... ;-)
Thanks for the points! Glad I could help!


Cheers!®©
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now