Posted on 2000-02-27
Medium Priority
Last Modified: 2010-05-02
I have a calculation field where there should only be a numeric input.  I suppose there should be an isnumeric verification on the change event but I'm not sure how to write it.
Question by:douglaskarr
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
  • 3
  • 2

Accepted Solution

Vbmaster earned 40 total points
ID: 2562729
Here's a easy way to not allow the end user to enter any non-digits value into a textbox..

  Private Sub Text1_KeyPress(KeyAscii As Integer)

    If Not ((KeyAscii >= vbKey0) And (KeyAscii <= vbKey9)) Then
      KeyAscii = 0
    End If

  End Sub

This will only allow the keys 0 to 9.

Author Comment

ID: 2562745

Author Comment

ID: 2562750
Hold on... what about decimals?  ie: 5.1

Expert Comment

ID: 2562829
This would be a solution, it checks to make sure the input is numerical values and it will allow one decimal point (46 is the ascii code for the '.' character)...

  If Not ((KeyAscii >= vbKey0) And (KeyAscii <= vbKey9)) Then
    If Not ((KeyAscii = 46) And (InStr(Text1, ".") = 0)) Then
      KeyAscii = 0
    End If
  End If

Author Comment

ID: 2562881
Thank-you very much...


Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
Suggested Courses
Course of the Month9 days, 7 hours left to enroll

762 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