?
Solved

Limit entries in text box

Posted on 2000-03-19
3
Medium Priority
?
142 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 14

Accepted Solution

by:
mcrider earned 400 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

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…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month14 days, 6 hours left to enroll

771 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