Why doesn't this work? Just curious...

  • Thread starter Thread starter Gina Whipp
  • Start date Start date
G

Gina Whipp

Hello Anyone?

Why doesn't Example A work but Example B work?

Example A
If Me.txtLength > 0 And Me.txtCoilListGauge > 0 And Not
IsNull(TPID(Forms![frmOrder]![cboCustomerID], [txtLength],
[txtCoilListGauge])) Then
Me.txtTolling = TPID(Forms![frmOrder]![cboCustomerID], [txtLength],
[txtCoilListGauge]) & " lb."
Me.txtEstimatedPieces.Requery
Else
Me.txtTolling = TollingPrice([txtLength], [txtCoilListGauge]) & "
lb."
Me.txtEstimatedPieces.Requery
End If


Example B
If Me.txtLength > 0 And Me.txtCoilListGauge > 0 And Not
IsNull(TPID(Forms![frmOrder]![cboCustomerID], [txtLength],
[txtCoilListGauge])) Then
Me.txtTolling = TPID(Forms![frmOrder]![cboCustomerID], [txtLength],
[txtCoilListGauge]) & " lb."
Me.txtEstimatedPieces.Requery
End If

If Me.txtLength > 0 And Me.txtCoilListGauge > 0 And
IsNull(TPID(Forms![frmOrder]![cboCustomerID], [txtLength],
[txtCoilListGauge])) Then
Me.txtTolling = TollingPrice([txtLength], [txtCoilListGauge]) & "
lb."
Me.txtEstimatedPieces.Requery
End If

Thanks,
Gina
 
In Example A, if either (or both) txtLength or txtCoilListGauge = 0, then
the condition is False and Me.txtTolling = TollingPrice([txtLength],
[txtCoilListGauge]). I'm guessing that means TollingPrice = 0.

In Example B, both txtLength and txtCoilListGauge have to be > 0 for
Me.txtTolling = TollingPrice([txtLength], [txtCoilListGauge]).

Maybe you want something like the following?:

If Me.txtLength > 0 And Me.txtCoilListGauge > 0 Then
If Not IsNull(TPID(Forms![frmOrder]![cboCustomerID], [txtLength],
[txtCoilListGauge])) Then
Me.txtTolling = TPID(Forms![frmOrder]![cboCustomerID], [txtLength],
[txtCoilListGauge]) & " lb."
Else
Me.txtTolling = TollingPrice([txtLength], [txtCoilListGauge]) & "
lb."
End If
Else
' Not sure this is necessary....
Me.txtTolling = 0
End If
Me.txtEstimatedPieces.Requery


HTH,
 
I think maybe I should have been clearer.

Example A uses Else
Example B is 2 seperate statements

They both should come to the same conclusion, however, when I use the Else
statement it doesn't work. If I seperate the logic into 2 statements it
works.

What I am saying is:

If [txtLength]>0 and [txtGauge]>0 and Not IsNull(TPID....)
then Me.txtTolling = TollingPrice(...)

OR

If [txtLength]>0 and [txtGauge]>0 and IsNull(TPID....)
then Me.txtTolling = TPID(...)

It's the Not IsNull / IsNull that is different. Hope I expalined that
better.

Gina

George Nicholson said:
In Example A, if either (or both) txtLength or txtCoilListGauge = 0, then
the condition is False and Me.txtTolling = TollingPrice([txtLength],
[txtCoilListGauge]). I'm guessing that means TollingPrice = 0.

In Example B, both txtLength and txtCoilListGauge have to be > 0 for
Me.txtTolling = TollingPrice([txtLength], [txtCoilListGauge]).

Maybe you want something like the following?:

If Me.txtLength > 0 And Me.txtCoilListGauge > 0 Then
If Not IsNull(TPID(Forms![frmOrder]![cboCustomerID], [txtLength],
[txtCoilListGauge])) Then
Me.txtTolling = TPID(Forms![frmOrder]![cboCustomerID], [txtLength],
[txtCoilListGauge]) & " lb."
Else
Me.txtTolling = TollingPrice([txtLength], [txtCoilListGauge]) & "
lb."
End If
Else
' Not sure this is necessary....
Me.txtTolling = 0
End If
Me.txtEstimatedPieces.Requery


HTH,
--
George Nicholson

Remove 'Junk' from return address.


Gina Whipp said:
Hello Anyone?

Why doesn't Example A work but Example B work?

Example A
If Me.txtLength > 0 And Me.txtCoilListGauge > 0 And Not
IsNull(TPID(Forms![frmOrder]![cboCustomerID], [txtLength],
[txtCoilListGauge])) Then
Me.txtTolling = TPID(Forms![frmOrder]![cboCustomerID],
[txtLength], [txtCoilListGauge]) & " lb."
Me.txtEstimatedPieces.Requery
Else
Me.txtTolling = TollingPrice([txtLength], [txtCoilListGauge]) & "
lb."
Me.txtEstimatedPieces.Requery
End If


Example B
If Me.txtLength > 0 And Me.txtCoilListGauge > 0 And Not
IsNull(TPID(Forms![frmOrder]![cboCustomerID], [txtLength],
[txtCoilListGauge])) Then
Me.txtTolling = TPID(Forms![frmOrder]![cboCustomerID],
[txtLength], [txtCoilListGauge]) & " lb."
Me.txtEstimatedPieces.Requery
End If

If Me.txtLength > 0 And Me.txtCoilListGauge > 0 And
IsNull(TPID(Forms![frmOrder]![cboCustomerID], [txtLength],
[txtCoilListGauge])) Then
Me.txtTolling = TollingPrice([txtLength], [txtCoilListGauge]) & "
lb."
Me.txtEstimatedPieces.Requery
End If

Thanks,
Gina
 
You missed my point, but I could've been clearer. :-)

Your 2 examples start off the same but divurge significantly and will
provide different results

ExampleA - Part 1: If 1 ,2 and 3 are ALL True, do this.
ExampleA - Part 1: otherwise do this (i.e., if *any* or *all* of 1, 2, 3 are
False)

ExampleB - part 1: If 1, 2 and 3 are ALL True, do this.
ExampleB - part 2: If both 1 and 2 are True and 3 is False, do this.

Your Part 1's are the same. Your Part 2's are not. Example A will act, one
way or the other, on ALL permutations of the 3 conditions. Example B only
acts on TTT and TTF. It does nothing with TFF, FTF, FFT and FFF
permutations. I have to assume the "do nothing" aspect is what you like
about the results of Example B (you never did provide a definition of "it
works", but I didn't ask either.).

Since it seems you only want to act when 1 and 2 are both True, I broke that
out as a primary condition. Only when that condition is met do you need to
do a nested 2nd check for Null and react accordingly.

HTH,
--
George Nicholson

Remove 'Junk' from return address.


Gina Whipp said:
I think maybe I should have been clearer.

Example A uses Else
Example B is 2 seperate statements

They both should come to the same conclusion, however, when I use the Else
statement it doesn't work. If I seperate the logic into 2 statements it
works.

What I am saying is:

If [txtLength]>0 and [txtGauge]>0 and Not IsNull(TPID....)
then Me.txtTolling = TollingPrice(...)

OR

If [txtLength]>0 and [txtGauge]>0 and IsNull(TPID....)
then Me.txtTolling = TPID(...)

It's the Not IsNull / IsNull that is different. Hope I expalined that
better.

Gina

George Nicholson said:
In Example A, if either (or both) txtLength or txtCoilListGauge = 0, then
the condition is False and Me.txtTolling = TollingPrice([txtLength],
[txtCoilListGauge]). I'm guessing that means TollingPrice = 0.

In Example B, both txtLength and txtCoilListGauge have to be > 0 for
Me.txtTolling = TollingPrice([txtLength], [txtCoilListGauge]).

Maybe you want something like the following?:

If Me.txtLength > 0 And Me.txtCoilListGauge > 0 Then
If Not IsNull(TPID(Forms![frmOrder]![cboCustomerID], [txtLength],
[txtCoilListGauge])) Then
Me.txtTolling = TPID(Forms![frmOrder]![cboCustomerID],
[txtLength], [txtCoilListGauge]) & " lb."
Else
Me.txtTolling = TollingPrice([txtLength], [txtCoilListGauge]) & "
lb."
End If
Else
' Not sure this is necessary....
Me.txtTolling = 0
End If
Me.txtEstimatedPieces.Requery


HTH,
--
George Nicholson

Remove 'Junk' from return address.


Gina Whipp said:
Hello Anyone?

Why doesn't Example A work but Example B work?

Example A
If Me.txtLength > 0 And Me.txtCoilListGauge > 0 And Not
IsNull(TPID(Forms![frmOrder]![cboCustomerID], [txtLength],
[txtCoilListGauge])) Then
Me.txtTolling = TPID(Forms![frmOrder]![cboCustomerID],
[txtLength], [txtCoilListGauge]) & " lb."
Me.txtEstimatedPieces.Requery
Else
Me.txtTolling = TollingPrice([txtLength], [txtCoilListGauge]) & "
lb."
Me.txtEstimatedPieces.Requery
End If


Example B
If Me.txtLength > 0 And Me.txtCoilListGauge > 0 And Not
IsNull(TPID(Forms![frmOrder]![cboCustomerID], [txtLength],
[txtCoilListGauge])) Then
Me.txtTolling = TPID(Forms![frmOrder]![cboCustomerID],
[txtLength], [txtCoilListGauge]) & " lb."
Me.txtEstimatedPieces.Requery
End If

If Me.txtLength > 0 And Me.txtCoilListGauge > 0 And
IsNull(TPID(Forms![frmOrder]![cboCustomerID], [txtLength],
[txtCoilListGauge])) Then
Me.txtTolling = TollingPrice([txtLength], [txtCoilListGauge]) & "
lb."
Me.txtEstimatedPieces.Requery
End If

Thanks,
Gina
 
Okay, I understand now.... thanks for taking the time to explain it. I
guess I didn't COMPLETELY read your answer.

Thanks,
Gina

George Nicholson said:
You missed my point, but I could've been clearer. :-)

Your 2 examples start off the same but divurge significantly and will
provide different results

ExampleA - Part 1: If 1 ,2 and 3 are ALL True, do this.
ExampleA - Part 1: otherwise do this (i.e., if *any* or *all* of 1, 2, 3
are False)

ExampleB - part 1: If 1, 2 and 3 are ALL True, do this.
ExampleB - part 2: If both 1 and 2 are True and 3 is False, do this.

Your Part 1's are the same. Your Part 2's are not. Example A will act,
one way or the other, on ALL permutations of the 3 conditions. Example B
only acts on TTT and TTF. It does nothing with TFF, FTF, FFT and FFF
permutations. I have to assume the "do nothing" aspect is what you like
about the results of Example B (you never did provide a definition of "it
works", but I didn't ask either.).

Since it seems you only want to act when 1 and 2 are both True, I broke
that out as a primary condition. Only when that condition is met do you
need to do a nested 2nd check for Null and react accordingly.

HTH,
--
George Nicholson

Remove 'Junk' from return address.


Gina Whipp said:
I think maybe I should have been clearer.

Example A uses Else
Example B is 2 seperate statements

They both should come to the same conclusion, however, when I use the
Else statement it doesn't work. If I seperate the logic into 2
statements it works.

What I am saying is:

If [txtLength]>0 and [txtGauge]>0 and Not IsNull(TPID....)
then Me.txtTolling = TollingPrice(...)

OR

If [txtLength]>0 and [txtGauge]>0 and IsNull(TPID....)
then Me.txtTolling = TPID(...)

It's the Not IsNull / IsNull that is different. Hope I expalined that
better.

Gina

George Nicholson said:
In Example A, if either (or both) txtLength or txtCoilListGauge = 0,
then the condition is False and Me.txtTolling =
TollingPrice([txtLength], [txtCoilListGauge]). I'm guessing that means
TollingPrice = 0.

In Example B, both txtLength and txtCoilListGauge have to be > 0 for
Me.txtTolling = TollingPrice([txtLength], [txtCoilListGauge]).

Maybe you want something like the following?:

If Me.txtLength > 0 And Me.txtCoilListGauge > 0 Then
If Not IsNull(TPID(Forms![frmOrder]![cboCustomerID], [txtLength],
[txtCoilListGauge])) Then
Me.txtTolling = TPID(Forms![frmOrder]![cboCustomerID],
[txtLength], [txtCoilListGauge]) & " lb."
Else
Me.txtTolling = TollingPrice([txtLength], [txtCoilListGauge]) & "
lb."
End If
Else
' Not sure this is necessary....
Me.txtTolling = 0
End If
Me.txtEstimatedPieces.Requery


HTH,
--
George Nicholson

Remove 'Junk' from return address.


Hello Anyone?

Why doesn't Example A work but Example B work?

Example A
If Me.txtLength > 0 And Me.txtCoilListGauge > 0 And Not
IsNull(TPID(Forms![frmOrder]![cboCustomerID], [txtLength],
[txtCoilListGauge])) Then
Me.txtTolling = TPID(Forms![frmOrder]![cboCustomerID],
[txtLength], [txtCoilListGauge]) & " lb."
Me.txtEstimatedPieces.Requery
Else
Me.txtTolling = TollingPrice([txtLength], [txtCoilListGauge]) &
" lb."
Me.txtEstimatedPieces.Requery
End If


Example B
If Me.txtLength > 0 And Me.txtCoilListGauge > 0 And Not
IsNull(TPID(Forms![frmOrder]![cboCustomerID], [txtLength],
[txtCoilListGauge])) Then
Me.txtTolling = TPID(Forms![frmOrder]![cboCustomerID],
[txtLength], [txtCoilListGauge]) & " lb."
Me.txtEstimatedPieces.Requery
End If

If Me.txtLength > 0 And Me.txtCoilListGauge > 0 And
IsNull(TPID(Forms![frmOrder]![cboCustomerID], [txtLength],
[txtCoilListGauge])) Then
Me.txtTolling = TollingPrice([txtLength], [txtCoilListGauge]) &
" lb."
Me.txtEstimatedPieces.Requery
End If

Thanks,
Gina
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top