Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Conditional expressions in forms

Status
Not open for further replies.

dtutton

Technical User
Mar 28, 2001
58
DE
Can one put conditional expressions in the Control Source of a text box.

i.e. Currently

=[TireCost]/[TireLife]

but if TireLife=0 I get a divide by zero which I need to trap, can one do something like

=if(Tirelife=0,0,Tirecost/Tirelife)

as in excel !

David
 
You bet David!

First method is probably the best. Shouldn't tire life always be >0 ? In your table for the tire life field type >0 in to the "Validation Rule" property. (Same on your form's field if it's already made. Now in the "Validation Text" you would write something like:

Tire life must always be greater than 0!

Other choice is the "Immediate If":

=IIf([TireCost]=0,0,[TireLife]/[TireCost])

you were so close, and Access can be so fussy. :) Gord
ghubbell@total.net
 
Easy -Thanks again. Ill take a look for a book - living in Germany doesnt let me browse Access books in English in a bookshop so Ill try ordering your recommendation.

Let say the if became more complex, I guess then Id have to go to some vba, where would this be on the Control of the text box or the control of the form and could one use something similar to the expression ? The books that I have seem mainly on the gui and database functions rather than the vba elements - because of the ease of programming I used to (and still do) write all my technical applications in clipper - with dos dying with the newer windows version - I guess I have to learn vba more.

Thanks, David
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top