I can't figure out how to incorporate this...

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

Gina Whipp

Hello All,

What I want to say is...

If IsNull([txtSkidPrice]) Or Me.txtSkidPrice = 0 Then ...Do the below Else
CancelEvent

I am already using the below code and it works fine. I just want to
incorporate the top part, can someone show me how or tell me how?

If cSkidPrice([txtCustomerID], [cboSkidCodeID], [txtCoilListWidth],
[txtLength]) > 0 Then
Me.txtSkidPrice = cSkidPrice([txtCustomerID], [cboSkidCodeID],
[txtCoilListWidth], [txtLength])
Else
Me.txtSkidPrice = SkidPrice([cboSkidCodeID], [txtCoilListWidth],
[txtLength])
End If

As Always, Big THANKS
Gina
 
Will this work?

If Not IsNull([txtSkidPrice]) Or Me.txtSkidPrice > 0 Then
DoCmd.CancelEvent
Else
If cSkidPrice([txtCustomerID], [cboSkidCodeID], [txtCoilListWidth],
[txtLength]) > 0 Then
Me.txtSkidPrice = cSkidPrice([txtCustomerID], [cboSkidCodeID],
[txtCoilListWidth], [txtLength])
Else
Me.txtSkidPrice = SkidPrice([cboSkidCodeID], [txtCoilListWidth],
[txtLength])
End If
End If
 
Without seeing all the code, I would think you could just do

If NZ(Me.[txtSkidPrice],0) = 0 Then

If cSkidPrice([txtCustomerID], [cboSkidCodeID], [txtCoilListWidth],
[txtLength]) > 0 Then
Me.txtSkidPrice = cSkidPrice([txtCustomerID], [cboSkidCodeID],
[txtCoilListWidth], [txtLength])
Else
Me.txtSkidPrice = SkidPrice([cboSkidCodeID], [txtCoilListWidth],
[txtLength])
End If
End IF
 
But since I want the event cancelled, can I use...

If Not IsNull([txtSkidPrice]) Or Me.txtSkidPrice > 0 Then
DoCmd.CancelEvent
Else
If cSkidPrice([txtCustomerID], [cboSkidCodeID], [txtCoilListWidth],
[txtLength]) > 0 Then
Me.txtSkidPrice = cSkidPrice([txtCustomerID], [cboSkidCodeID],
[txtCoilListWidth], [txtLength])
Else
Me.txtSkidPrice = SkidPrice([cboSkidCodeID], [txtCoilListWidth],
[txtLength])
End If
End If

John Spencer said:
Without seeing all the code, I would think you could just do

If NZ(Me.[txtSkidPrice],0) = 0 Then

If cSkidPrice([txtCustomerID], [cboSkidCodeID], [txtCoilListWidth],
[txtLength]) > 0 Then
Me.txtSkidPrice = cSkidPrice([txtCustomerID], [cboSkidCodeID],
[txtCoilListWidth], [txtLength])
Else
Me.txtSkidPrice = SkidPrice([cboSkidCodeID], [txtCoilListWidth],
[txtLength])
End If
End IF


Gina Whipp said:
Hello All,

What I want to say is...

If IsNull([txtSkidPrice]) Or Me.txtSkidPrice = 0 Then ...Do the below
Else CancelEvent

I am already using the below code and it works fine. I just want to
incorporate the top part, can someone show me how or tell me how?

If cSkidPrice([txtCustomerID], [cboSkidCodeID], [txtCoilListWidth],
[txtLength]) > 0 Then
Me.txtSkidPrice = cSkidPrice([txtCustomerID], [cboSkidCodeID],
[txtCoilListWidth], [txtLength])
Else
Me.txtSkidPrice = SkidPrice([cboSkidCodeID], [txtCoilListWidth],
[txtLength])
End If

As Always, Big THANKS
Gina
 
PMFJI,

Gina,

What John did is combine both conditions into one by using the NZ()
function. (I have to remember this)

If [txtSkidPrice] is null, the NZ() function converts it to a zero. Then all
you have to do is test for a zero. Presto!! No worries about nulls.

Now about the DoCmd.CancelEvent. Pretend the Sub looks like this:

Sub CalcSomething()
If NZ(Me.[txtSkidPrice],0) = 0 Then
 
Steve,

Thanks for the explanation, I myself forget about Nz() function BUT

Referring to my DoCmd.CancelEvent (I need to learn/understand these things).
I want it to cancel all the code and leave it 0 (zero) because the 0
actually prompts another event, putting in the price manually, which you are
suppose to do.

So, if I am understanding correctly, the way I did will work and the way
John did it will work also?

Thanks for taking the time,
Gina


SteveS said:
PMFJI,

Gina,

What John did is combine both conditions into one by using the NZ()
function. (I have to remember this)

If [txtSkidPrice] is null, the NZ() function converts it to a zero. Then
all
you have to do is test for a zero. Presto!! No worries about nulls.

Now about the DoCmd.CancelEvent. Pretend the Sub looks like this:

Sub CalcSomething()
If NZ(Me.[txtSkidPrice],0) = 0 Then
.
.
.
. A lot of lines to calc something
.
.
End If
End Sub

So if Me.[txtSkidPrice] = 0, what happens? You skip down to the END IF and
execute the next line, which is END SUB.

By putting the IF() around all the code (if [txtSkidPrice] = 0) , it is,
in
effect, canceling the event/actions/calcs.

Nice and concise.

HTH
--
Steve S
--------------------------------
"Veni, Vidi, Velcro"
(I came; I saw; I stuck around.)


Gina Whipp said:
But since I want the event cancelled, can I use...

If Not IsNull([txtSkidPrice]) Or Me.txtSkidPrice > 0 Then
DoCmd.CancelEvent
Else
If cSkidPrice([txtCustomerID], [cboSkidCodeID],
[txtCoilListWidth],
[txtLength]) > 0 Then
Me.txtSkidPrice = cSkidPrice([txtCustomerID],
[cboSkidCodeID],
[txtCoilListWidth], [txtLength])
Else
Me.txtSkidPrice = SkidPrice([cboSkidCodeID],
[txtCoilListWidth],
[txtLength])
End If
End If

John Spencer said:
Without seeing all the code, I would think you could just do

If NZ(Me.[txtSkidPrice],0) = 0 Then

If cSkidPrice([txtCustomerID], [cboSkidCodeID], [txtCoilListWidth],
[txtLength]) > 0 Then
Me.txtSkidPrice = cSkidPrice([txtCustomerID], [cboSkidCodeID],
[txtCoilListWidth], [txtLength])
Else
Me.txtSkidPrice = SkidPrice([cboSkidCodeID], [txtCoilListWidth],
[txtLength])
End If
End IF


Hello All,

What I want to say is...

If IsNull([txtSkidPrice]) Or Me.txtSkidPrice = 0 Then ...Do the
below
Else CancelEvent

I am already using the below code and it works fine. I just want to
incorporate the top part, can someone show me how or tell me how?

If cSkidPrice([txtCustomerID], [cboSkidCodeID], [txtCoilListWidth],
[txtLength]) > 0 Then
Me.txtSkidPrice = cSkidPrice([txtCustomerID], [cboSkidCodeID],
[txtCoilListWidth], [txtLength])
Else
Me.txtSkidPrice = SkidPrice([cboSkidCodeID],
[txtCoilListWidth],
[txtLength])
End If

As Always, Big THANKS
Gina
 
Yes and No.

Yes, both ways will work; if the field [txtSkidPrice] is Null or zero, John's
example will not run the code within the IF() function, your example will run
the statements in the True block.

No, if [txtSkidPrice] is null, it will still be null after the IF() function.
The NZ() function does not change the value in the field, just how it is seen
(like the Format() function. If other code should run if the value of the field
is zero, then you need to add code to replace the Null in the field with zero.

Like John said, without seeing all of the code , it is hard to be 100% sure of
what will (or should) happen.

Steve S.
--------------------------------
"Veni, Vidi, Velcro"
(I came, I saw, I stuck around.)

Gina said:
Steve,

Thanks for the explanation, I myself forget about Nz() function BUT

Referring to my DoCmd.CancelEvent (I need to learn/understand these things).
I want it to cancel all the code and leave it 0 (zero) because the 0
actually prompts another event, putting in the price manually, which you are
suppose to do.

So, if I am understanding correctly, the way I did will work and the way
John did it will work also?

Thanks for taking the time,
Gina


PMFJI,

Gina,

What John did is combine both conditions into one by using the NZ()
function. (I have to remember this)

If [txtSkidPrice] is null, the NZ() function converts it to a zero. Then
all
you have to do is test for a zero. Presto!! No worries about nulls.

Now about the DoCmd.CancelEvent. Pretend the Sub looks like this:

Sub CalcSomething()
If NZ(Me.[txtSkidPrice],0) = 0 Then
.
.
.
. A lot of lines to calc something
.
.
End If
End Sub

So if Me.[txtSkidPrice] = 0, what happens? You skip down to the END IF and
execute the next line, which is END SUB.

By putting the IF() around all the code (if [txtSkidPrice] = 0) , it is,
in
effect, canceling the event/actions/calcs.

Nice and concise.

HTH
--
Steve S
--------------------------------
"Veni, Vidi, Velcro"
(I came; I saw; I stuck around.)


:

But since I want the event cancelled, can I use...

If Not IsNull([txtSkidPrice]) Or Me.txtSkidPrice > 0 Then
DoCmd.CancelEvent
Else
If cSkidPrice([txtCustomerID], [cboSkidCodeID],
[txtCoilListWidth],
[txtLength]) > 0 Then
Me.txtSkidPrice = cSkidPrice([txtCustomerID],
[cboSkidCodeID],
[txtCoilListWidth], [txtLength])
Else
Me.txtSkidPrice = SkidPrice([cboSkidCodeID],
[txtCoilListWidth],
[txtLength])
End If
End If


Without seeing all the code, I would think you could just do

If NZ(Me.[txtSkidPrice],0) = 0 Then

If cSkidPrice([txtCustomerID], [cboSkidCodeID], [txtCoilListWidth],
[txtLength]) > 0 Then
Me.txtSkidPrice = cSkidPrice([txtCustomerID], [cboSkidCodeID],
[txtCoilListWidth], [txtLength])
Else
Me.txtSkidPrice = SkidPrice([cboSkidCodeID], [txtCoilListWidth],
[txtLength])
End If
End IF



Hello All,

What I want to say is...

If IsNull([txtSkidPrice]) Or Me.txtSkidPrice = 0 Then ...Do the
below
Else CancelEvent

I am already using the below code and it works fine. I just want to
incorporate the top part, can someone show me how or tell me how?

If cSkidPrice([txtCustomerID], [cboSkidCodeID], [txtCoilListWidth],
[txtLength]) > 0 Then
Me.txtSkidPrice = cSkidPrice([txtCustomerID], [cboSkidCodeID],
[txtCoilListWidth], [txtLength])
Else
Me.txtSkidPrice = SkidPrice([cboSkidCodeID],
[txtCoilListWidth],
[txtLength])
End If

As Always, Big THANKS
Gina
 
Below is the entrie code from that section and it appears to work. If the
field is "" OR 0 it opens sfrOrderPricing where you have to enter a price
which is exactly what I want.

Private Sub cboSkidCodeID_AfterUpdate()
If Not IsNull([txtSkidPrice]) Or Me.txtSkidPrice > 0 Then
DoCmd.CancelEvent
Else
If cSkidPrice([txtCustomerID], [cboSkidCodeID], [txtCoilListWidth],
[txtLength]) > 0 Then
Me.txtSkidPrice = cSkidPrice([txtCustomerID], [cboSkidCodeID],
[txtCoilListWidth], [txtLength])
Else
Me.txtSkidPrice = SkidPrice([cboSkidCodeID], [txtCoilListWidth],
[txtLength])
End If
End If

If Me.txtSkidPrice = "" Or Me.txtSkidPrice = 0 Then
DoCmd.OpenForm "sfrOrderPricing", acNormal, , "[oeOrderDetailID]=" &
Me![txtOrderDetailID]
End If
End Sub

SteveS said:
Yes and No.

Yes, both ways will work; if the field [txtSkidPrice] is Null or zero,
John's example will not run the code within the IF() function, your
example will run the statements in the True block.

No, if [txtSkidPrice] is null, it will still be null after the IF()
function. The NZ() function does not change the value in the field, just
how it is seen (like the Format() function. If other code should run if
the value of the field is zero, then you need to add code to replace the
Null in the field with zero.

Like John said, without seeing all of the code , it is hard to be 100%
sure of what will (or should) happen.

Steve S.
--------------------------------
"Veni, Vidi, Velcro"
(I came, I saw, I stuck around.)

Gina said:
Steve,

Thanks for the explanation, I myself forget about Nz() function BUT

Referring to my DoCmd.CancelEvent (I need to learn/understand these
things). I want it to cancel all the code and leave it 0 (zero) because
the 0 actually prompts another event, putting in the price manually,
which you are suppose to do.

So, if I am understanding correctly, the way I did will work and the way
John did it will work also?

Thanks for taking the time,
Gina


PMFJI,

Gina,

What John did is combine both conditions into one by using the NZ()
function. (I have to remember this)

If [txtSkidPrice] is null, the NZ() function converts it to a zero. Then
all
you have to do is test for a zero. Presto!! No worries about nulls.

Now about the DoCmd.CancelEvent. Pretend the Sub looks like this:

Sub CalcSomething()
If NZ(Me.[txtSkidPrice],0) = 0 Then
.
.
.
. A lot of lines to calc something
.
.
End If
End Sub

So if Me.[txtSkidPrice] = 0, what happens? You skip down to the END IF
and
execute the next line, which is END SUB.

By putting the IF() around all the code (if [txtSkidPrice] = 0) , it is,
in
effect, canceling the event/actions/calcs.

Nice and concise.

HTH
--
Steve S
--------------------------------
"Veni, Vidi, Velcro"
(I came; I saw; I stuck around.)


:


But since I want the event cancelled, can I use...

If Not IsNull([txtSkidPrice]) Or Me.txtSkidPrice > 0 Then
DoCmd.CancelEvent
Else
If cSkidPrice([txtCustomerID], [cboSkidCodeID],
[txtCoilListWidth],
[txtLength]) > 0 Then
Me.txtSkidPrice = cSkidPrice([txtCustomerID],
[cboSkidCodeID],
[txtCoilListWidth], [txtLength])
Else
Me.txtSkidPrice = SkidPrice([cboSkidCodeID],
[txtCoilListWidth],
[txtLength])
End If
End If


Without seeing all the code, I would think you could just do

If NZ(Me.[txtSkidPrice],0) = 0 Then

If cSkidPrice([txtCustomerID], [cboSkidCodeID], [txtCoilListWidth],
[txtLength]) > 0 Then
Me.txtSkidPrice = cSkidPrice([txtCustomerID], [cboSkidCodeID],
[txtCoilListWidth], [txtLength])
Else
Me.txtSkidPrice = SkidPrice([cboSkidCodeID], [txtCoilListWidth],
[txtLength])
End If
End IF



Hello All,

What I want to say is...

If IsNull([txtSkidPrice]) Or Me.txtSkidPrice = 0 Then ...Do the
below
Else CancelEvent

I am already using the below code and it works fine. I just want to
incorporate the top part, can someone show me how or tell me how?

If cSkidPrice([txtCustomerID], [cboSkidCodeID], [txtCoilListWidth],
[txtLength]) > 0 Then
Me.txtSkidPrice = cSkidPrice([txtCustomerID], [cboSkidCodeID],
[txtCoilListWidth], [txtLength])
Else
Me.txtSkidPrice = SkidPrice([cboSkidCodeID],
[txtCoilListWidth],
[txtLength])
End If

As Always, Big THANKS
Gina
 
Gina,

Yes, your cboSkidCodeID_AfterUpdate() code will work fine. If you are happy
with it and understand it, great.

Every one has their own personal Coding style. Mine changes as I see "better"
ways (browsing this NG) of coding.

---

Using John's example, the after update event code would like this:
(watch for line wrap)
'***
Private Sub cboSkidCodeID_AfterUpdate()
If Nz([txtSkidPrice], 0) = 0 Then

If cSkidPrice([txtCustomerID], [cboSkidCodeID], [txtCoilListWidth],
[txtLength]) > 0 Then
Me.txtSkidPrice = cSkidPrice([txtCustomerID], [cboSkidCodeID],
[txtCoilListWidth], [txtLength])
Else
Me.txtSkidPrice = SkidPrice([cboSkidCodeID], [txtCoilListWidth],
[txtLength])
End If

If Me.txtSkidPrice = "" Or Me.txtSkidPrice = 0 Then
DoCmd.OpenForm "sfrOrderPricing", acNormal, , "[oeOrderDetailID]=" &
Me![txtOrderDetailID]
End If

End If
End Sub
'****

If [txtSkidPrice] > 0, it falls thru to the END SUB line; DoCmd.CancelEvent is
not needed.

-----

I would have used EXIT SUB instead of DoCmd.CancelEvent. But they do the same
thing - some lines of code are not executed. So, another way of writing it
would be:

'***
Private Sub cboSkidCodeID_AfterUpdate()
If Nz([txtSkidPrice], 0) > 0 Then
Exit Sub
End If

If cSkidPrice([txtCustomerID], [cboSkidCodeID], [txtCoilListWidth],
[txtLength]) > 0 Then
Me.txtSkidPrice = cSkidPrice([txtCustomerID], [cboSkidCodeID],
[txtCoilListWidth], [txtLength])
Else
Me.txtSkidPrice = SkidPrice([cboSkidCodeID], [txtCoilListWidth],
[txtLength])
End If

If Me.txtSkidPrice = "" Or Me.txtSkidPrice = 0 Then
DoCmd.OpenForm "sfrOrderPricing", acNormal, , "[oeOrderDetailID]=" &
Me![txtOrderDetailID]
End If

End Sub
'***

---

Less code is less to troubleshoot and less code is a faster application.

For example, you do a custom function cSkidPrice() calculation twice. You could
rewrite the code like this:

'**
Private Sub cboSkidCodeID2_AfterUpdate()
Dim tmpPrice As Currency

If Nz([txtSkidPrice], 0) > 0 Then
Exit Sub
End If

tmpPrice = cSkidPrice([txtCustomerID], [cboSkidCodeID], [txtCoilListWidth],
[txtLength])

If tmpPrice > 0 Then '<<<<<
Me.txtSkidPrice = tmpPrice '<<<<<
Else
Me.txtSkidPrice = SkidPrice([cboSkidCodeID], [txtCoilListWidth],
[txtLength])
End If

If Me.txtSkidPrice = "" Or Me.txtSkidPrice = 0 Then
DoCmd.OpenForm "sfrOrderPricing", acNormal, , "[oeOrderDetailID]=" &
Me![txtOrderDetailID]
End If

End Sub
'***
---

Anyway, your code works and you understand it. :)

Sooooooooo, I'm going to go glue my fingers together so I'll stop typing.......


--
Steve S.
--------------------------------
"Veni, Vidi, Velcro"
(I came, I saw, I stuck around.)

Gina said:
Below is the entrie code from that section and it appears to work. If the
field is "" OR 0 it opens sfrOrderPricing where you have to enter a price
which is exactly what I want.

Private Sub cboSkidCodeID_AfterUpdate()
If Not IsNull([txtSkidPrice]) Or Me.txtSkidPrice > 0 Then
DoCmd.CancelEvent
Else
If cSkidPrice([txtCustomerID], [cboSkidCodeID], [txtCoilListWidth],
[txtLength]) > 0 Then
Me.txtSkidPrice = cSkidPrice([txtCustomerID], [cboSkidCodeID],
[txtCoilListWidth], [txtLength])
Else
Me.txtSkidPrice = SkidPrice([cboSkidCodeID], [txtCoilListWidth],
[txtLength])
End If
End If

If Me.txtSkidPrice = "" Or Me.txtSkidPrice = 0 Then
DoCmd.OpenForm "sfrOrderPricing", acNormal, , "[oeOrderDetailID]=" &
Me![txtOrderDetailID]
End If
End Sub

Yes and No.

Yes, both ways will work; if the field [txtSkidPrice] is Null or zero,
John's example will not run the code within the IF() function, your
example will run the statements in the True block.

No, if [txtSkidPrice] is null, it will still be null after the IF()
function. The NZ() function does not change the value in the field, just
how it is seen (like the Format() function. If other code should run if
the value of the field is zero, then you need to add code to replace the
Null in the field with zero.

Like John said, without seeing all of the code , it is hard to be 100%
sure of what will (or should) happen.

Steve S.
--------------------------------
"Veni, Vidi, Velcro"
(I came, I saw, I stuck around.)

Gina said:
Steve,

Thanks for the explanation, I myself forget about Nz() function BUT

Referring to my DoCmd.CancelEvent (I need to learn/understand these
things). I want it to cancel all the code and leave it 0 (zero) because
the 0 actually prompts another event, putting in the price manually,
which you are suppose to do.

So, if I am understanding correctly, the way I did will work and the way
John did it will work also?

Thanks for taking the time,
Gina


"SteveS" <sanfu at techie dot com> wrote in message


PMFJI,

Gina,

What John did is combine both conditions into one by using the NZ()
function. (I have to remember this)

If [txtSkidPrice] is null, the NZ() function converts it to a zero. Then
all
you have to do is test for a zero. Presto!! No worries about nulls.

Now about the DoCmd.CancelEvent. Pretend the Sub looks like this:

Sub CalcSomething()
If NZ(Me.[txtSkidPrice],0) = 0 Then
.
.
.
. A lot of lines to calc something
.
.
End If
End Sub

So if Me.[txtSkidPrice] = 0, what happens? You skip down to the END IF
and
execute the next line, which is END SUB.

By putting the IF() around all the code (if [txtSkidPrice] = 0) , it is,
in
effect, canceling the event/actions/calcs.

Nice and concise.

HTH
--
Steve S
--------------------------------
"Veni, Vidi, Velcro"
(I came; I saw; I stuck around.)


:



But since I want the event cancelled, can I use...

If Not IsNull([txtSkidPrice]) Or Me.txtSkidPrice > 0 Then
DoCmd.CancelEvent
Else
If cSkidPrice([txtCustomerID], [cboSkidCodeID],
[txtCoilListWidth],
[txtLength]) > 0 Then
Me.txtSkidPrice = cSkidPrice([txtCustomerID],
[cboSkidCodeID],
[txtCoilListWidth], [txtLength])
Else
Me.txtSkidPrice = SkidPrice([cboSkidCodeID],
[txtCoilListWidth],
[txtLength])
End If
End If



Without seeing all the code, I would think you could just do

If NZ(Me.[txtSkidPrice],0) = 0 Then

If cSkidPrice([txtCustomerID], [cboSkidCodeID], [txtCoilListWidth],
[txtLength]) > 0 Then
Me.txtSkidPrice = cSkidPrice([txtCustomerID], [cboSkidCodeID],
[txtCoilListWidth], [txtLength])
Else
Me.txtSkidPrice = SkidPrice([cboSkidCodeID], [txtCoilListWidth],
[txtLength])
End If
End IF




Hello All,

What I want to say is...

If IsNull([txtSkidPrice]) Or Me.txtSkidPrice = 0 Then ...Do the
below
Else CancelEvent

I am already using the below code and it works fine. I just want to
incorporate the top part, can someone show me how or tell me how?

If cSkidPrice([txtCustomerID], [cboSkidCodeID], [txtCoilListWidth],
[txtLength]) > 0 Then
Me.txtSkidPrice = cSkidPrice([txtCustomerID], [cboSkidCodeID],
[txtCoilListWidth], [txtLength])
Else
Me.txtSkidPrice = SkidPrice([cboSkidCodeID],
[txtCoilListWidth],
[txtLength])
End If

As Always, Big THANKS
Gina
 
Steve,

The key is I understand it BUT it's always nice to see another way to 'skin
the cat' that is less painful on the cat or is the on the skinner?
Anyway...

I too like to see other ways that will run faster and make it easier to
troubleshoot IF there is a problem. (The learning never stops.) Thanks for
the suggestions AND I have printed them off so I can UNDERSTAND it and
perhaps use it!

Thanks,
Gina

SteveS said:
Gina,

Yes, your cboSkidCodeID_AfterUpdate() code will work fine. If you are
happy with it and understand it, great.

Every one has their own personal Coding style. Mine changes as I see
"better" ways (browsing this NG) of coding.

---

Using John's example, the after update event code would like this:
(watch for line wrap)
'***
Private Sub cboSkidCodeID_AfterUpdate()
If Nz([txtSkidPrice], 0) = 0 Then

If cSkidPrice([txtCustomerID], [cboSkidCodeID], [txtCoilListWidth],
[txtLength]) > 0 Then
Me.txtSkidPrice = cSkidPrice([txtCustomerID], [cboSkidCodeID],
[txtCoilListWidth], [txtLength])
Else
Me.txtSkidPrice = SkidPrice([cboSkidCodeID], [txtCoilListWidth],
[txtLength])
End If

If Me.txtSkidPrice = "" Or Me.txtSkidPrice = 0 Then
DoCmd.OpenForm "sfrOrderPricing", acNormal, ,
"[oeOrderDetailID]=" & Me![txtOrderDetailID]
End If

End If
End Sub
'****

If [txtSkidPrice] > 0, it falls thru to the END SUB line;
DoCmd.CancelEvent is not needed.

-----

I would have used EXIT SUB instead of DoCmd.CancelEvent. But they do the
same thing - some lines of code are not executed. So, another way of
writing it would be:

'***
Private Sub cboSkidCodeID_AfterUpdate()
If Nz([txtSkidPrice], 0) > 0 Then
Exit Sub
End If

If cSkidPrice([txtCustomerID], [cboSkidCodeID], [txtCoilListWidth],
[txtLength]) > 0 Then
Me.txtSkidPrice = cSkidPrice([txtCustomerID], [cboSkidCodeID],
[txtCoilListWidth], [txtLength])
Else
Me.txtSkidPrice = SkidPrice([cboSkidCodeID], [txtCoilListWidth],
[txtLength])
End If

If Me.txtSkidPrice = "" Or Me.txtSkidPrice = 0 Then
DoCmd.OpenForm "sfrOrderPricing", acNormal, , "[oeOrderDetailID]=" &
Me![txtOrderDetailID]
End If

End Sub
'***

---

Less code is less to troubleshoot and less code is a faster application.

For example, you do a custom function cSkidPrice() calculation twice. You
could rewrite the code like this:

'**
Private Sub cboSkidCodeID2_AfterUpdate()
Dim tmpPrice As Currency

If Nz([txtSkidPrice], 0) > 0 Then
Exit Sub
End If

tmpPrice = cSkidPrice([txtCustomerID], [cboSkidCodeID],
[txtCoilListWidth], [txtLength])

If tmpPrice > 0 Then '<<<<<
Me.txtSkidPrice = tmpPrice '<<<<<
Else
Me.txtSkidPrice = SkidPrice([cboSkidCodeID], [txtCoilListWidth],
[txtLength])
End If

If Me.txtSkidPrice = "" Or Me.txtSkidPrice = 0 Then
DoCmd.OpenForm "sfrOrderPricing", acNormal, , "[oeOrderDetailID]=" &
Me![txtOrderDetailID]
End If

End Sub
'***
---

Anyway, your code works and you understand it. :)

Sooooooooo, I'm going to go glue my fingers together so I'll stop
typing.......


--
Steve S.
--------------------------------
"Veni, Vidi, Velcro"
(I came, I saw, I stuck around.)

Gina said:
Below is the entrie code from that section and it appears to work. If
the field is "" OR 0 it opens sfrOrderPricing where you have to enter a
price which is exactly what I want.

Private Sub cboSkidCodeID_AfterUpdate()
If Not IsNull([txtSkidPrice]) Or Me.txtSkidPrice > 0 Then
DoCmd.CancelEvent
Else
If cSkidPrice([txtCustomerID], [cboSkidCodeID],
[txtCoilListWidth], [txtLength]) > 0 Then
Me.txtSkidPrice = cSkidPrice([txtCustomerID],
[cboSkidCodeID], [txtCoilListWidth], [txtLength])
Else
Me.txtSkidPrice = SkidPrice([cboSkidCodeID],
[txtCoilListWidth], [txtLength])
End If
End If

If Me.txtSkidPrice = "" Or Me.txtSkidPrice = 0 Then
DoCmd.OpenForm "sfrOrderPricing", acNormal, ,
"[oeOrderDetailID]=" & Me![txtOrderDetailID]
End If
End Sub

Yes and No.

Yes, both ways will work; if the field [txtSkidPrice] is Null or zero,
John's example will not run the code within the IF() function, your
example will run the statements in the True block.

No, if [txtSkidPrice] is null, it will still be null after the IF()
function. The NZ() function does not change the value in the field, just
how it is seen (like the Format() function. If other code should run if
the value of the field is zero, then you need to add code to replace the
Null in the field with zero.

Like John said, without seeing all of the code , it is hard to be 100%
sure of what will (or should) happen.

Steve S.
--------------------------------
"Veni, Vidi, Velcro"
(I came, I saw, I stuck around.)

Gina Whipp wrote:

Steve,

Thanks for the explanation, I myself forget about Nz() function BUT

Referring to my DoCmd.CancelEvent (I need to learn/understand these
things). I want it to cancel all the code and leave it 0 (zero) because
the 0 actually prompts another event, putting in the price manually,
which you are suppose to do.

So, if I am understanding correctly, the way I did will work and the way
John did it will work also?

Thanks for taking the time,
Gina


"SteveS" <sanfu at techie dot com> wrote in message


PMFJI,

Gina,

What John did is combine both conditions into one by using the NZ()
function. (I have to remember this)

If [txtSkidPrice] is null, the NZ() function converts it to a zero.
Then all
you have to do is test for a zero. Presto!! No worries about nulls.

Now about the DoCmd.CancelEvent. Pretend the Sub looks like this:

Sub CalcSomething()
If NZ(Me.[txtSkidPrice],0) = 0 Then
.
.
.
. A lot of lines to calc something
.
.
End If
End Sub

So if Me.[txtSkidPrice] = 0, what happens? You skip down to the END IF
and
execute the next line, which is END SUB.

By putting the IF() around all the code (if [txtSkidPrice] = 0) , it
is, in
effect, canceling the event/actions/calcs.

Nice and concise.

HTH
--
Steve S
--------------------------------
"Veni, Vidi, Velcro"
(I came; I saw; I stuck around.)


:



But since I want the event cancelled, can I use...

If Not IsNull([txtSkidPrice]) Or Me.txtSkidPrice > 0 Then
DoCmd.CancelEvent
Else
If cSkidPrice([txtCustomerID], [cboSkidCodeID],
[txtCoilListWidth],
[txtLength]) > 0 Then
Me.txtSkidPrice = cSkidPrice([txtCustomerID],
[cboSkidCodeID],
[txtCoilListWidth], [txtLength])
Else
Me.txtSkidPrice = SkidPrice([cboSkidCodeID],
[txtCoilListWidth],
[txtLength])
End If
End If



Without seeing all the code, I would think you could just do

If NZ(Me.[txtSkidPrice],0) = 0 Then

If cSkidPrice([txtCustomerID], [cboSkidCodeID], [txtCoilListWidth],
[txtLength]) > 0 Then
Me.txtSkidPrice = cSkidPrice([txtCustomerID], [cboSkidCodeID],
[txtCoilListWidth], [txtLength])
Else
Me.txtSkidPrice = SkidPrice([cboSkidCodeID],
[txtCoilListWidth],
[txtLength])
End If
End IF




Hello All,

What I want to say is...

If IsNull([txtSkidPrice]) Or Me.txtSkidPrice = 0 Then ...Do the
below
Else CancelEvent

I am already using the below code and it works fine. I just want to
incorporate the top part, can someone show me how or tell me how?

If cSkidPrice([txtCustomerID], [cboSkidCodeID],
[txtCoilListWidth],
[txtLength]) > 0 Then
Me.txtSkidPrice = cSkidPrice([txtCustomerID], [cboSkidCodeID],
[txtCoilListWidth], [txtLength])
Else
Me.txtSkidPrice = SkidPrice([cboSkidCodeID],
[txtCoilListWidth],
[txtLength])
End If

As Always, Big THANKS
Gina
 
By the way, like your way WAYYYYY better! Thanks!

SteveS said:
Gina,

Yes, your cboSkidCodeID_AfterUpdate() code will work fine. If you are
happy with it and understand it, great.

Every one has their own personal Coding style. Mine changes as I see
"better" ways (browsing this NG) of coding.

---

Using John's example, the after update event code would like this:
(watch for line wrap)
'***
Private Sub cboSkidCodeID_AfterUpdate()
If Nz([txtSkidPrice], 0) = 0 Then

If cSkidPrice([txtCustomerID], [cboSkidCodeID], [txtCoilListWidth],
[txtLength]) > 0 Then
Me.txtSkidPrice = cSkidPrice([txtCustomerID], [cboSkidCodeID],
[txtCoilListWidth], [txtLength])
Else
Me.txtSkidPrice = SkidPrice([cboSkidCodeID], [txtCoilListWidth],
[txtLength])
End If

If Me.txtSkidPrice = "" Or Me.txtSkidPrice = 0 Then
DoCmd.OpenForm "sfrOrderPricing", acNormal, ,
"[oeOrderDetailID]=" & Me![txtOrderDetailID]
End If

End If
End Sub
'****

If [txtSkidPrice] > 0, it falls thru to the END SUB line;
DoCmd.CancelEvent is not needed.

-----

I would have used EXIT SUB instead of DoCmd.CancelEvent. But they do the
same thing - some lines of code are not executed. So, another way of
writing it would be:

'***
Private Sub cboSkidCodeID_AfterUpdate()
If Nz([txtSkidPrice], 0) > 0 Then
Exit Sub
End If

If cSkidPrice([txtCustomerID], [cboSkidCodeID], [txtCoilListWidth],
[txtLength]) > 0 Then
Me.txtSkidPrice = cSkidPrice([txtCustomerID], [cboSkidCodeID],
[txtCoilListWidth], [txtLength])
Else
Me.txtSkidPrice = SkidPrice([cboSkidCodeID], [txtCoilListWidth],
[txtLength])
End If

If Me.txtSkidPrice = "" Or Me.txtSkidPrice = 0 Then
DoCmd.OpenForm "sfrOrderPricing", acNormal, , "[oeOrderDetailID]=" &
Me![txtOrderDetailID]
End If

End Sub
'***

---

Less code is less to troubleshoot and less code is a faster application.

For example, you do a custom function cSkidPrice() calculation twice. You
could rewrite the code like this:

'**
Private Sub cboSkidCodeID2_AfterUpdate()
Dim tmpPrice As Currency

If Nz([txtSkidPrice], 0) > 0 Then
Exit Sub
End If

tmpPrice = cSkidPrice([txtCustomerID], [cboSkidCodeID],
[txtCoilListWidth], [txtLength])

If tmpPrice > 0 Then '<<<<<
Me.txtSkidPrice = tmpPrice '<<<<<
Else
Me.txtSkidPrice = SkidPrice([cboSkidCodeID], [txtCoilListWidth],
[txtLength])
End If

If Me.txtSkidPrice = "" Or Me.txtSkidPrice = 0 Then
DoCmd.OpenForm "sfrOrderPricing", acNormal, , "[oeOrderDetailID]=" &
Me![txtOrderDetailID]
End If

End Sub
'***
---

Anyway, your code works and you understand it. :)

Sooooooooo, I'm going to go glue my fingers together so I'll stop
typing.......


--
Steve S.
--------------------------------
"Veni, Vidi, Velcro"
(I came, I saw, I stuck around.)

Gina said:
Below is the entrie code from that section and it appears to work. If
the field is "" OR 0 it opens sfrOrderPricing where you have to enter a
price which is exactly what I want.

Private Sub cboSkidCodeID_AfterUpdate()
If Not IsNull([txtSkidPrice]) Or Me.txtSkidPrice > 0 Then
DoCmd.CancelEvent
Else
If cSkidPrice([txtCustomerID], [cboSkidCodeID],
[txtCoilListWidth], [txtLength]) > 0 Then
Me.txtSkidPrice = cSkidPrice([txtCustomerID],
[cboSkidCodeID], [txtCoilListWidth], [txtLength])
Else
Me.txtSkidPrice = SkidPrice([cboSkidCodeID],
[txtCoilListWidth], [txtLength])
End If
End If

If Me.txtSkidPrice = "" Or Me.txtSkidPrice = 0 Then
DoCmd.OpenForm "sfrOrderPricing", acNormal, ,
"[oeOrderDetailID]=" & Me![txtOrderDetailID]
End If
End Sub

Yes and No.

Yes, both ways will work; if the field [txtSkidPrice] is Null or zero,
John's example will not run the code within the IF() function, your
example will run the statements in the True block.

No, if [txtSkidPrice] is null, it will still be null after the IF()
function. The NZ() function does not change the value in the field, just
how it is seen (like the Format() function. If other code should run if
the value of the field is zero, then you need to add code to replace the
Null in the field with zero.

Like John said, without seeing all of the code , it is hard to be 100%
sure of what will (or should) happen.

Steve S.
--------------------------------
"Veni, Vidi, Velcro"
(I came, I saw, I stuck around.)

Gina Whipp wrote:

Steve,

Thanks for the explanation, I myself forget about Nz() function BUT

Referring to my DoCmd.CancelEvent (I need to learn/understand these
things). I want it to cancel all the code and leave it 0 (zero) because
the 0 actually prompts another event, putting in the price manually,
which you are suppose to do.

So, if I am understanding correctly, the way I did will work and the way
John did it will work also?

Thanks for taking the time,
Gina


"SteveS" <sanfu at techie dot com> wrote in message


PMFJI,

Gina,

What John did is combine both conditions into one by using the NZ()
function. (I have to remember this)

If [txtSkidPrice] is null, the NZ() function converts it to a zero.
Then all
you have to do is test for a zero. Presto!! No worries about nulls.

Now about the DoCmd.CancelEvent. Pretend the Sub looks like this:

Sub CalcSomething()
If NZ(Me.[txtSkidPrice],0) = 0 Then
.
.
.
. A lot of lines to calc something
.
.
End If
End Sub

So if Me.[txtSkidPrice] = 0, what happens? You skip down to the END IF
and
execute the next line, which is END SUB.

By putting the IF() around all the code (if [txtSkidPrice] = 0) , it
is, in
effect, canceling the event/actions/calcs.

Nice and concise.

HTH
--
Steve S
--------------------------------
"Veni, Vidi, Velcro"
(I came; I saw; I stuck around.)


:



But since I want the event cancelled, can I use...

If Not IsNull([txtSkidPrice]) Or Me.txtSkidPrice > 0 Then
DoCmd.CancelEvent
Else
If cSkidPrice([txtCustomerID], [cboSkidCodeID],
[txtCoilListWidth],
[txtLength]) > 0 Then
Me.txtSkidPrice = cSkidPrice([txtCustomerID],
[cboSkidCodeID],
[txtCoilListWidth], [txtLength])
Else
Me.txtSkidPrice = SkidPrice([cboSkidCodeID],
[txtCoilListWidth],
[txtLength])
End If
End If



Without seeing all the code, I would think you could just do

If NZ(Me.[txtSkidPrice],0) = 0 Then

If cSkidPrice([txtCustomerID], [cboSkidCodeID], [txtCoilListWidth],
[txtLength]) > 0 Then
Me.txtSkidPrice = cSkidPrice([txtCustomerID], [cboSkidCodeID],
[txtCoilListWidth], [txtLength])
Else
Me.txtSkidPrice = SkidPrice([cboSkidCodeID],
[txtCoilListWidth],
[txtLength])
End If
End IF




Hello All,

What I want to say is...

If IsNull([txtSkidPrice]) Or Me.txtSkidPrice = 0 Then ...Do the
below
Else CancelEvent

I am already using the below code and it works fine. I just want to
incorporate the top part, can someone show me how or tell me how?

If cSkidPrice([txtCustomerID], [cboSkidCodeID],
[txtCoilListWidth],
[txtLength]) > 0 Then
Me.txtSkidPrice = cSkidPrice([txtCustomerID], [cboSkidCodeID],
[txtCoilListWidth], [txtLength])
Else
Me.txtSkidPrice = SkidPrice([cboSkidCodeID],
[txtCoilListWidth],
[txtLength])
End If

As Always, Big 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