problem of range validator

Gurmeet singh
Gurmeet singh used Ask the Experts™
on
i am filling a form of HPPSC, when i wants to update my information. there have a problem of range validator, what i can do?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Distinguished Expert 2017

Commented:
What is HPPSC?
What is the data that is causing the problem?
Dale FyeOwner, Dev-Soln LLC
Most Valuable Expert 2014
Top Expert 2010

Commented:
You can enforce range validation in several ways.
1.  You can define validation rules associated with a field in your tables.  Open the table in design view, select the field you want to validate or where the validation problem is occurring and define the new validation rules (I never put field validation rules in the table definition).

2.  Or you can modify your form to include field validation;  this is the way I generally do it.  Open the form in design view, select the Events tab of the properties dialog, then click the BeforeUpdate event; this event includes a Cancel argument which allows you to cancel the update process if you have fields that are required and don't have values entered, or if you want to test for values being within specified ranges.  My Before Update event code usually looks something like:
Private Sub Form_BeforeUpdate(Cancel as Integer)

    'Set the default value of the Cancel argument
    Cancel = true
    if Trim(me.txtField1Name & "") = "" Then
        msgbox "Please enter a value in Field1"
        me.txtField1Name.Setfocus
        Exit Sub
    elseif Trim(me.txtField2Name & "") = "" Then
        msgbox "Please enter a value in Field2"
        me.txtField2Name.Setfocus
        Exit Sub
    elseif Val(me.txtField2Name) < 0 OR Val(me.txtField2Name) > 100 then
        msgbox "Percent value cannot be less than zero or greater than 100"
        me.txtField2Name.SetFocus
        Exit Sub
    end if

    'If all fields pass the tests, then change the default value of the Cancel argument to false
    Cancel = false 

End Sub

Open in new window

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial