Why is this expression not calculating correctly? (1 Viewer)

Rich_B

Access Newbie
Local time
Today, 02:06
Joined
Feb 12, 2016
Messages
50
The expression below is not returning the result I expect.

=IIf(IsNull([MATERIAL]),"Select Material",([Height]*[Width]*[Length]/1000000000)*[QUANTITY])

Height = 140
Width = 150
Length = 1200
Quantity = 5

The result should be 0.126 but it's returning 10.2858

Any help appreciated.

Thank you
 
Last edited:

RuralGuy

AWF VIP
Local time
Yesterday, 19:06
Joined
Jul 2, 2005
Messages
13,825
Try:
(([Height]*[Width]*[Length])/1000000000)*[QUANTITY])
 

Minty

AWF VIP
Local time
Today, 02:06
Joined
Jul 26, 2013
Messages
10,379
The brackets don't cancel out and therefore this wouldn't work - so can you check that what you've typed is what is actually in your code ?
 

cyanidem

Nieóhfytny jaszczomp
Local time
Today, 02:06
Joined
Nov 30, 2015
Messages
106
Hmm...
Your fields are:
Code:
Height
Weight
Length
Quantity
But in calculation its:
Code:
Height
Width
Length
Quantity

Weight....Width...
 

Rich_B

Access Newbie
Local time
Today, 02:06
Joined
Feb 12, 2016
Messages
50
The brackets don't cancel out and therefore this wouldn't work - so can you check that what you've typed is what is actually in your code ?

Hi

The code is cut and pasted and the other specified values are definitely correct.

I assumed I had got the syntax wrong somewhere.
 

Rich_B

Access Newbie
Local time
Today, 02:06
Joined
Feb 12, 2016
Messages
50
Hmm...
Your fields are:
Code:
Height
Weight
Length
Quantity
But in calculation its:
Code:
Height
Width
Length
Quantity

Weight....Width...

That was a typo, now edited but the problem remains.

Thank you
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 09:06
Joined
May 7, 2009
Messages
19,248
=IIf(IsNull([MATERIAL]),"Select Material",([Height]*[Width]*[Length]/1000000000)*[QUANTITY])

should be:

=IIf(IsNull([MATERIAL]),"Select Material",([Height]*[Weight]*[Length]/1000000000)*[QUANTITY])
 

Minty

AWF VIP
Local time
Today, 02:06
Joined
Jul 26, 2013
Messages
10,379
Is this a form control source or in a query ?
What happens if you substitute hard coded values into the expression?
 

Rich_B

Access Newbie
Local time
Today, 02:06
Joined
Feb 12, 2016
Messages
50
=IIf(IsNull([MATERIAL]),"Select Material",([Height]*[Width]*[Length]/1000000000)*[QUANTITY])

should be:

=IIf(IsNull([MATERIAL]),"Select Material",([Height]*[Weight]*[Length]/1000000000)*[QUANTITY])

Thank you for your input.

Both are actually width. I just made a typo in the original post.

I'm still not getting the right result though.
 

Rich_B

Access Newbie
Local time
Today, 02:06
Joined
Feb 12, 2016
Messages
50
Is this a form control source or in a query ?
What happens if you substitute hard coded values into the expression?

It is a form control source.

I have substituted hard coded values and it works as expected.
 

Minty

AWF VIP
Local time
Today, 02:06
Joined
Jul 26, 2013
Messages
10,379
I wonder if it's because Height , Width and Length are possibly reserved names. What if you call them something else ?
 

cyanidem

Nieóhfytny jaszczomp
Local time
Today, 02:06
Joined
Nov 30, 2015
Messages
106
This is strange indeed, I made a query and a form based on table, entered your values and expression and... In query it works perfectly but on form I got result 9.70872.
 

cyanidem

Nieóhfytny jaszczomp
Local time
Today, 02:06
Joined
Nov 30, 2015
Messages
106
Changing names didn't change the result at all, also changing form sizes didn't matter. My result is still 9.70872.
I'm curious why is it different than OP's though.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 09:06
Joined
May 7, 2009
Messages
19,248
will using the name of textbox make difference. Me.theNameOfTextBox (not the control source).
 

Rich_B

Access Newbie
Local time
Today, 02:06
Joined
Feb 12, 2016
Messages
50
I wonder if it's because Height , Width and Length are possibly reserved names. What if you call them something else ?

That solved it. :)

I changed the field names to H, W & L and it all works fine now.

Thanks Minty
 

cyanidem

Nieóhfytny jaszczomp
Local time
Today, 02:06
Joined
Nov 30, 2015
Messages
106
Arnel wins. Referencing to the control name works, result is 0.126 now.
But why?
 

Users who are viewing this thread

Top Bottom