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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Math on a form 1

Status
Not open for further replies.

TimTDP

Technical User
Feb 15, 2004
373
0
0
ZA
In Access 2000 I have a form what contains 3 numerical fields, Quantity, Price & Factor.
Generally the result will be Quantity * Price, but I never know if the factor is to be multiplied or divided into this result. I have placed a combo box, called cboFactor, on the form whose row source is "*";"/";"+";"-"

I want to add a text field with the following control source:
=[Quantity]*[Price] & [cboFactor] & [Factor]
eg 10 * 3 / 2 or 10 * 4 / 8

What is the correct syntax to do this? Can I do it!?



 
How are ya TimTDP . . .

The problem is not the math, you have to take care of [blue]empty textboxes[/blue] as well as the infamous [blue]divide by zero![/blue] Copy/paste the following:
Code:
[blue]=IIf(IsNull([Quantity]) Or IsNull([Price]) Or IsNull([cboFactor]) Or IsNull([Factor]),Null,[purple][b]Switch([/b][/purple][cboFactor]="*",(Nz([Quantity])*Nz([Price]))*Nz([Factor]),[cboFactor]="/",(Nz([Quantity])*Nz([Price]))/Nz([Factor]),[cboFactor]="+",(Nz([Quantity])*Nz([Price]))+Nz([Factor]),[cboFactor]="-",(Nz([Quantity])*Nz([Price]))-Nz([Factor]),0=0,Null[purple][b])[/b][/purple])[/blue]
The key here is the [blue]Switch[/blue] function.

[blue]Your Thoughts? . . .[/blue]

Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997
Also faq181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top