Results 1 to 7 of 7
  1. #1
    Join Date
    Jan 2002
    Location
    Bay Area
    Posts
    511

    Smile Unanswered: Need Correct Technique to Validate if Numeric

    I would like to know the correct technique to validate whether text typed into a combo box is a whole number. I was unable to conquer the MASK property of the combo box because, with the mask 99999, the value passed to VBA for 1000 was 1000_

    What does work is assigning the combo text to a numeric varible, for example, in the combo box UPDATE event:

    ON ERROR GOTO NOT_A_NUMBER:
    MyNumericVar = cboTargets.Text
    ON ERROR GOTO 0
    ...more code

    Exit Sub

    NOT_A_NUMBER:
    Msgbox "Enter only a number in the box"
    Exit Sub

    I would like to know the correct method of data validation of a value typed into a text box to ensure that the value is numeric.

    Thanks.

  2. #2
    Join Date
    Nov 2002
    Posts
    150

    Re: Need Correct Technique to Validate if Numeric

    Hmmm, I didn't get the 1000_ problem for a mask of 99999.

    Question: is the combo bound or unbound?

  3. #3
    Join Date
    Jan 2002
    Location
    Bay Area
    Posts
    511
    The combo is unbound. When I tried to use the MASK wizard, there was no option to not use a place holder, so the underscore was chosen. I removed this in the combo box properties window changing it from 99999;;_ to 99999, but the values passed shorter than 5 characters still had the underscore.

    Jerry

  4. #4
    Join Date
    Nov 2002
    Posts
    150
    I just typed 99999 into the Input Mask property and it worked for both bound and unbound combo's.

    Since a user is typing stuff in, is it a combo that accepts data not in the list?

  5. #5
    Join Date
    Jan 2002
    Location
    Bay Area
    Posts
    511
    The combo accepts anything and is not limited to the list box. As soon as I change the combo box mask to 99999, when I click on the combo box the underscore appears, 5 together.

  6. #6
    Join Date
    Feb 2002
    Posts
    2,232
    Try the following in your combo boxes keypress event - if a user enter a non numeric character nothing is displayed:

    If Not (KeyAscii > 47 And KeyAscii < 58) Then
    KeyAscii = 0
    End If

  7. #7
    Join Date
    Jan 2002
    Location
    Bay Area
    Posts
    511

    Talking

    It works! Now the text box accepts only numbers with your solution:

    If Not (KeyAscii > 47 And KeyAscii < 58) Then
    KeyAscii = 0
    End If

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •