80 pts.
 How to validate 2 fields
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.

Software/Hardware used:
ASKED: June 9, 2010  7:39 AM
UPDATED: June 20, 2010  9:36 PM

Answer Wiki:
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.
Last Wiki Answer Submitted:  June 9, 2010  1:49 pm  by  carlosdl   63,535 pts.
All Answer Wiki Contributors:  carlosdl   63,535 pts.
To see all answers submitted to the Answer Wiki: View Answer History.


Discuss This Question:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _


 

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 pts.

 

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 pts.

 

You can use the table constraint:

([FuelAmount]=0 and [FuelLiters]=0) Or ([FuelAmount]>0 And [FuelLiters]>0)

 1,610 pts.

 

Thanks for your reply. But Sorry! i couldnt understand “table constraint” where this statement put., please reply

 80 pts.

 

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
 63,535 pts.

 

> 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,610 pts.

 

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 pts.