How to validate 2 fields

80 pts.
Tags:
Database
Form validations
I have a transaction table, There are 2 fields FuelLiters & FuelAmount. Both should be >0 or =0. If by mistaken FuelLiters entered as 0 and FuelAmount >0, computer should prompt about this mistake.

Answer Wiki

Thanks. We'll let you know when a new response is added.

You didn’t provide any details about the programming language and the database being used.

In general, you could perform such validation in your application, or with a database check constraint.

Discuss This Question: 7  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • Abdul30dec
    I have a transaction table, There are 2 fields FuelLiters & FuelAmount. Both should be >0 or =0. If by mistaken FuelLiters entered as 0 and FuelAmount >0, computer should prompt about this mistake.
    80 pointsBadges:
    report
  • Abdul30dec
    I have a transaction table, There are 2 fields FuelLiters & FuelAmount. Both should be >0 or =0. If by mistaken FuelLiters entered as 0 and FuelAmount >0, system should prompt about this mistake. I am using MS Access-2000 Thanks
    80 pointsBadges:
    report
  • msi77
    You can use the table constraint: ([FuelAmount]=0 and [FuelLiters]=0) Or ([FuelAmount]>0 And [FuelLiters]>0)
    1,670 pointsBadges:
    report
  • Abdul30dec
    Thanks for your reply. But Sorry! i couldnt understand "table constraint" where this statement put., please reply
    80 pointsBadges:
    report
  • carlosdl
    I'm not sure if this will work on Access 2000. You could create a Visual Basic module withsome code like this:
    Private Sub AddCheckConstraint()
    CurrentProject.Connection.Execute _
    "alter table YourTable add constraint YourContraintName check (([FuelAmount]=0 and [FuelLiters]=0) Or ([FuelAmount]>0 And [FuelLiters]>0))"
    End Sub
    69,510 pointsBadges:
    report
  • msi77
    > But Sorry! i couldnt understand “table constraint” where this statement put., please reply Type it in the Validation Rule field of the table property
    1,670 pointsBadges:
    report
  • 49cubes
    As Carlosdl said... u can either handle it at the application end before record gets inserted into the transactions table or u can use a database check constraint on the field to handle it. You can also u a database TRIGGER to handle that on the event of an "INSERT" into the transactions table. ....(ie if ur database supports triggers).
    45 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following