Simple math not working ...

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Ok, I have some code that is going off no matter what number is being
inputted and i have no idea why.
AU is a double defined earlier in the code.

The part that is going off every time is:
ElseIf AU > (Me![Order Amount] - Nz(Me![Amount Received], 0)) Then
MsgBox ("You Have Entered " & AU & " Items Received Yet Only " &
(Me![Order Amount] - Nz(Me![Amount Received], 0)) & " Was Expected!")

For example: AU is 0 via the inputbox, [Order Amount] is 1, [Amount
Received] is null

Then it should read: elseif 0 > (1-0) then ....
I have verified that the numbers are correct yet it is going here
everytime and never skipping it.

Can anyone tell me what I am doing wrong here?


--------------------------------------------------------------------------------------
AU = InputBox("Enter The Partial Amount Received!", "Partial Amount
Received!")

If IsNull(AU) Or AU = "" Then
Exit Sub
ElseIf AU > (Me![Order Amount] - Nz(Me![Amount Received], 0)) Then
MsgBox ("You Have Entered " & AU & " Items Received Yet Only " &
(Me![Order Amount] - Nz(Me![Amount Received], 0)) & " Was Expected!")
Exit Sub
Else
'bulk of code here
End If
 
Aye, I've done that and everything checks out good.

I'm stumped.

Alex Dybenko said:
Hi,
you can put a stop at mentioned line, and then examine each value in
immediate window like:
?AU

?Me![Order Amount]

?(Me![Order Amount] - Nz(Me![Amount Received], 0))

this will help you to find what is going wrong

--
Best regards,
___________
Alex Dybenko (MVP)
http://alexdyb.blogspot.com
http://www.PointLtd.com

Lythandra said:
Ok, I have some code that is going off no matter what number is being
inputted and i have no idea why.
AU is a double defined earlier in the code.

The part that is going off every time is:
ElseIf AU > (Me![Order Amount] - Nz(Me![Amount Received], 0)) Then
MsgBox ("You Have Entered " & AU & " Items Received Yet Only " &
(Me![Order Amount] - Nz(Me![Amount Received], 0)) & " Was Expected!")

For example: AU is 0 via the inputbox, [Order Amount] is 1, [Amount
Received] is null

Then it should read: elseif 0 > (1-0) then ....
I have verified that the numbers are correct yet it is going here
everytime and never skipping it.

Can anyone tell me what I am doing wrong here?


--------------------------------------------------------------------------------------
AU = InputBox("Enter The Partial Amount Received!", "Partial Amount
Received!")

If IsNull(AU) Or AU = "" Then
Exit Sub
ElseIf AU > (Me![Order Amount] - Nz(Me![Amount Received], 0)) Then
MsgBox ("You Have Entered " & AU & " Items Received Yet Only " &
(Me![Order Amount] - Nz(Me![Amount Received], 0)) & " Was Expected!")
Exit Sub
Else
'bulk of code here
End If
 
Interesting, Look at this:

?AU
0
?(Me![Order Amount] - Nz(Me![Amount Received], 0))
38 <----notice the space in front

?AU
0
?Trim((Me![Order Amount] - Nz(Me![Amount Received], 0)))
38 <-----no space

Why would it put a space in front of the calculation? Everything is taken
from number fields.

It seems to be working with the Trim added tho.

Any thoughts on why the space is being added?

Thanks


Lythandra said:
Aye, I've done that and everything checks out good.

I'm stumped.

Alex Dybenko said:
Hi,
you can put a stop at mentioned line, and then examine each value in
immediate window like:
?AU

?Me![Order Amount]

?(Me![Order Amount] - Nz(Me![Amount Received], 0))

this will help you to find what is going wrong

--
Best regards,
___________
Alex Dybenko (MVP)
http://alexdyb.blogspot.com
http://www.PointLtd.com

Lythandra said:
Ok, I have some code that is going off no matter what number is being
inputted and i have no idea why.
AU is a double defined earlier in the code.

The part that is going off every time is:
ElseIf AU > (Me![Order Amount] - Nz(Me![Amount Received], 0)) Then
MsgBox ("You Have Entered " & AU & " Items Received Yet Only " &
(Me![Order Amount] - Nz(Me![Amount Received], 0)) & " Was Expected!")

For example: AU is 0 via the inputbox, [Order Amount] is 1, [Amount
Received] is null

Then it should read: elseif 0 > (1-0) then ....
I have verified that the numbers are correct yet it is going here
everytime and never skipping it.

Can anyone tell me what I am doing wrong here?


--------------------------------------------------------------------------------------
AU = InputBox("Enter The Partial Amount Received!", "Partial Amount
Received!")

If IsNull(AU) Or AU = "" Then
Exit Sub
ElseIf AU > (Me![Order Amount] - Nz(Me![Amount Received], 0)) Then
MsgBox ("You Have Entered " & AU & " Items Received Yet Only " &
(Me![Order Amount] - Nz(Me![Amount Received], 0)) & " Was Expected!")
Exit Sub
Else
'bulk of code here
End If
 
Ok, it seems that my inputbox is being seen as a string even tho I have the
variable for it defined as a number.

How to I force it to be a number? Specifically single.

Thanks



Lythandra said:
Interesting, Look at this:

?AU
0
?(Me![Order Amount] - Nz(Me![Amount Received], 0))
38 <----notice the space in front

?AU
0
?Trim((Me![Order Amount] - Nz(Me![Amount Received], 0)))
38 <-----no space

Why would it put a space in front of the calculation? Everything is taken
from number fields.

It seems to be working with the Trim added tho.

Any thoughts on why the space is being added?

Thanks


Lythandra said:
Aye, I've done that and everything checks out good.

I'm stumped.

Alex Dybenko said:
Hi,
you can put a stop at mentioned line, and then examine each value in
immediate window like:
?AU

?Me![Order Amount]

?(Me![Order Amount] - Nz(Me![Amount Received], 0))

this will help you to find what is going wrong

--
Best regards,
___________
Alex Dybenko (MVP)
http://alexdyb.blogspot.com
http://www.PointLtd.com

Ok, I have some code that is going off no matter what number is being
inputted and i have no idea why.
AU is a double defined earlier in the code.

The part that is going off every time is:
ElseIf AU > (Me![Order Amount] - Nz(Me![Amount Received], 0)) Then
MsgBox ("You Have Entered " & AU & " Items Received Yet Only " &
(Me![Order Amount] - Nz(Me![Amount Received], 0)) & " Was Expected!")

For example: AU is 0 via the inputbox, [Order Amount] is 1, [Amount
Received] is null

Then it should read: elseif 0 > (1-0) then ....
I have verified that the numbers are correct yet it is going here
everytime and never skipping it.

Can anyone tell me what I am doing wrong here?


--------------------------------------------------------------------------------------
AU = InputBox("Enter The Partial Amount Received!", "Partial Amount
Received!")

If IsNull(AU) Or AU = "" Then
Exit Sub
ElseIf AU > (Me![Order Amount] - Nz(Me![Amount Received], 0)) Then
MsgBox ("You Have Entered " & AU & " Items Received Yet Only " &
(Me![Order Amount] - Nz(Me![Amount Received], 0)) & " Was Expected!")
Exit Sub
Else
'bulk of code here
End If
 
I got it.

Using an InputBox forced my variable to a string even tho I had it as a
double which was causing all my weird looking errors.

I did a CDbl(Variable) to force it back to my desired type and viola all
started working.

I am sane again. ;-)

Lythandra said:
Ok, it seems that my inputbox is being seen as a string even tho I have the
variable for it defined as a number.

How to I force it to be a number? Specifically single.

Thanks



Lythandra said:
Interesting, Look at this:

?AU
0
?(Me![Order Amount] - Nz(Me![Amount Received], 0))
38 <----notice the space in front

?AU
0
?Trim((Me![Order Amount] - Nz(Me![Amount Received], 0)))
38 <-----no space

Why would it put a space in front of the calculation? Everything is taken
from number fields.

It seems to be working with the Trim added tho.

Any thoughts on why the space is being added?

Thanks


Lythandra said:
Aye, I've done that and everything checks out good.

I'm stumped.

:

Hi,
you can put a stop at mentioned line, and then examine each value in
immediate window like:
?AU

?Me![Order Amount]

?(Me![Order Amount] - Nz(Me![Amount Received], 0))

this will help you to find what is going wrong

--
Best regards,
___________
Alex Dybenko (MVP)
http://alexdyb.blogspot.com
http://www.PointLtd.com

Ok, I have some code that is going off no matter what number is being
inputted and i have no idea why.
AU is a double defined earlier in the code.

The part that is going off every time is:
ElseIf AU > (Me![Order Amount] - Nz(Me![Amount Received], 0)) Then
MsgBox ("You Have Entered " & AU & " Items Received Yet Only " &
(Me![Order Amount] - Nz(Me![Amount Received], 0)) & " Was Expected!")

For example: AU is 0 via the inputbox, [Order Amount] is 1, [Amount
Received] is null

Then it should read: elseif 0 > (1-0) then ....
I have verified that the numbers are correct yet it is going here
everytime and never skipping it.

Can anyone tell me what I am doing wrong here?


--------------------------------------------------------------------------------------
AU = InputBox("Enter The Partial Amount Received!", "Partial Amount
Received!")

If IsNull(AU) Or AU = "" Then
Exit Sub
ElseIf AU > (Me![Order Amount] - Nz(Me![Amount Received], 0)) Then
MsgBox ("You Have Entered " & AU & " Items Received Yet Only " &
(Me![Order Amount] - Nz(Me![Amount Received], 0)) & " Was Expected!")
Exit Sub
Else
'bulk of code here
End If
 
Input boxes *always* return strings (even if its an empty string). Its up to
the programmer to then verify the returned value and, if necessary, coerce
it to something they can work with.



Lythandra said:
I got it.

Using an InputBox forced my variable to a string even tho I had it as a
double which was causing all my weird looking errors.

I did a CDbl(Variable) to force it back to my desired type and viola all
started working.

I am sane again. ;-)

Lythandra said:
Ok, it seems that my inputbox is being seen as a string even tho I have
the
variable for it defined as a number.

How to I force it to be a number? Specifically single.

Thanks



Lythandra said:
Interesting, Look at this:

?AU
0
?(Me![Order Amount] - Nz(Me![Amount Received], 0))
38 <----notice the space in front

?AU
0
?Trim((Me![Order Amount] - Nz(Me![Amount Received], 0)))
38 <-----no space

Why would it put a space in front of the calculation? Everything is
taken
from number fields.

It seems to be working with the Trim added tho.

Any thoughts on why the space is being added?

Thanks


:

Aye, I've done that and everything checks out good.

I'm stumped.

:

Hi,
you can put a stop at mentioned line, and then examine each value
in
immediate window like:
?AU

?Me![Order Amount]

?(Me![Order Amount] - Nz(Me![Amount Received], 0))

this will help you to find what is going wrong

--
Best regards,
___________
Alex Dybenko (MVP)
http://alexdyb.blogspot.com
http://www.PointLtd.com

Ok, I have some code that is going off no matter what number is
being
inputted and i have no idea why.
AU is a double defined earlier in the code.

The part that is going off every time is:
ElseIf AU > (Me![Order Amount] - Nz(Me![Amount Received], 0))
Then
MsgBox ("You Have Entered " & AU & " Items Received Yet
Only " &
(Me![Order Amount] - Nz(Me![Amount Received], 0)) & " Was
Expected!")

For example: AU is 0 via the inputbox, [Order Amount] is 1,
[Amount
Received] is null

Then it should read: elseif 0 > (1-0) then ....
I have verified that the numbers are correct yet it is
going here
everytime and never skipping it.

Can anyone tell me what I am doing wrong here?


--------------------------------------------------------------------------------------
AU = InputBox("Enter The Partial Amount Received!", "Partial
Amount
Received!")

If IsNull(AU) Or AU = "" Then
Exit Sub
ElseIf AU > (Me![Order Amount] - Nz(Me![Amount Received], 0))
Then
MsgBox ("You Have Entered " & AU & " Items Received Yet
Only " &
(Me![Order Amount] - Nz(Me![Amount Received], 0)) & " Was
Expected!")
Exit Sub
Else
'bulk of code here
End If
 
Back
Top