Results 1 to 5 of 5
  1. #1
    Join Date
    Jan 2004
    Posts
    13

    Unanswered: Error Message when field is 0

    Hi,

    I am new to VBA,

    I have a formfield which I want to give a message if the value is zero (the default value), so the user must input a number, before moving on to the next field...

    I have tried this.

    Private Sub RGR_Number_AfterUpdate()
    Dim RGRNo As Integer

    If (RGRNo) = 0 Then
    MsgBox "enter RGR number"

    End If
    End Sub

    Whats the best way of doing this, (are their any tuitorials on this sort of thing).

    Regards
    Allen

  2. #2
    Join Date
    Jan 2004
    Location
    Bedford, UK
    Posts
    5

    Re: Error Message when field is 0

    It looks as if you should have:

    If cint(RGR_Number.text)=o Then

    etc.

    All the best David

  3. #3
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    You may also want to refocus the control to ensure the user cannot move on without entering an appropriate value:

    Private Sub RGR_Number_AfterUpdate()
    Dim RGRNo As Integer

    If (RGRNo) = 0 Then
    MsgBox "enter RGR number"

    RGR_Number.SetFocus

    End If
    End Sub

  4. #4
    Join Date
    Oct 2003
    Posts
    706

    Exclamation

    If input is required, and zero is not an acceptable value to be entered, then there should be no "default value" at all, and the field should be marked Required.

    When any "bright-line rules" exist for the acceptable values of a field, such as "NOT NULL" or a range-of-values or other similar validation, then you should, where possible, implement these as constraint rules directly in the table. The same is true of defaults: you don't have to have one. If you do have one, it should be an acceptable or plausible value. Insofar as is practical, "a table should not suffer invalid data to be placed into it by any means whatever." (That's not always too "practical" since, of course, s**t happens.)

    Also: as a rule, I prefer to let the user type in whatever values he/she wishes into a field, then validate the form full of data all-at-once, versus field-at-a-time. Takes a little more effort but I prefer it.
    ChimneySweep(R): fast, automatic
    table repair at a click of the
    mouse! http://www.sundialservices.com

  5. #5
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    Originally posted by sundialsvcs
    Also: as a rule, I prefer to let the user type in whatever values he/she wishes into a field, then validate the form full of data all-at-once, versus field-at-a-time. Takes a little more effort but I prefer it.
    Agreed.

    I implement some form of "error checking" in every dynamic report that I use. For me it's fairly easy as I simply have to check for null:
    Code:
    If IsNull(MyTxtBox) Then
        MsgBox("Please enter a valid mytxtbox value.")
        End
    ElseIf (AnotherCondtion maybe a type cast to check for validity) Then
        MsgBox("Another error.")
        End
    Else
       Code to execute if error checking succeeds
    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
  •