Solved

Limit entries in text box

Posted on 2000-03-19
3
137 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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

757 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

18 Experts available now in Live!

Get 1:1 Help Now