Results 1 to 3 of 3
  1. #1
    Join Date
    Sep 2010

    Unanswered: Validation in VB on text boxes

    I'm trying to add some validation into some text boxes on a form in access.

    I have three text boxes and all i want is to make sure the value is numeric and is not null but no matter what I try it doesn't seem to work. I have a button that adds the values in my form into the database and I'm trying to add the validation into the coding of the button.

    My code looks like then

    If isnumeric (txtstart) = false or isnumeric (txtend) = false or isnumeric (txtvalue) = false then
    MsgBox "A numeric value must be entered in each field"
    If txtstart = "" or txtend="" or txtvalue="" then
    MsgBox "A value must be entered into each field"

    this is where I have my command

    End if
    End if

    Am i on the right lines or have I got it totally wrong?

  2. #2
    Join Date
    Nov 2004
    out on a limb
    Provided Answers: 59
    first off consider setting an input mask for the controls
    next consider using VBA to check that the data is numeric

    you could do that in the controls "on change" event
    allowing the user to input only 0..9 plus whatever your local decimal symbol is, plus whatever your local thousand separator plus tab and carriage return
    if its not one of those characters then either play a beep or raise an error message
    I'd rather be riding on the Tiger 800 or the Norton

  3. #3
    Join Date
    Feb 2004
    One Flump in One Place
    Just to make a point about your method of validation, IsNumeric likely does not do what you think it does:
    Public Sub Yikes()
        Debug.Print IsNumeric(12)
        Debug.Print IsNumeric("12")
        Debug.Print IsNumeric(Null)
        Debug.Print IsNumeric("3e5")
        Debug.Print IsNumeric("3d5")
        Debug.Print IsNumeric("3,5")
        Debug.Print IsNumeric("3,5,6")
        Debug.Print IsNumeric("&H1")
        Debug.Print IsNumeric(&H1)
        Debug.Print "---------"
        Debug.Print Not 12 Like "*[!0-9.]*"
        Debug.Print Not "12" Like "*[!0-9.]*"
        Debug.Print Not Null Like "*[!0-9.]*"
        Debug.Print Not "3e5" Like "*[!0-9.]*"
        Debug.Print Not "3d5" Like "*[!0-9.]*"
        Debug.Print Not "3,5" Like "*[!0-9.]*"
        Debug.Print Not "3,5,6" Like "*[!0-9.]*"
        Debug.Print Not "&H1" Like "*[!0-9.]*"
        Debug.Print Not &H1 Like "*[!0-9.]*"
    End Sub
    pootle flump
    ur codings are working excelent.

Posting Permissions

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