Solved

Limit entries in text box

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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Using "ScreenUpdating" 6 84
vb6 connector to mongodb 2 142
RUNRMTCMD from AS/400 13 101
Assign a value in Excel V-Basic 3 29
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

726 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