Nested IF

D

DS

This doesn't seem to be working....It just keeps running any idea why?
Thanks
DS

If Me.Location = Bar Then
With Forms!Sales.SalesDetails.Form.Recordset
If Forms!Sales.SalesDetails.Form!Text127 = 0 Then
Do While .EOF = False And .BOF = False
.MoveFirst
.Edit
!SDInclusive = True
!SDTaxed = False
.Update
.MoveNext
Loop
End If
End With
Else
With Forms!Sales.SalesDetails.Form.Recordset
If Forms!Sales.SalesDetails.Form!Text127 = 0 Then
Do While .EOF = False And .BOF = False
.MoveFirst
.Edit
!SDInclusive = False
!SDTaxed = True
.Update
.MoveNext
Loop
End If
End With
End If
DoCmd.GoToRecord , , acLast
End Sub
 
M

mike

You have the .MoveFirst inside the loop. Every iteration, it just goes right
back to the first record. Put the .MoveFirst before the Do While statement.
 
D

DS

mike said:
You have the .MoveFirst inside the loop. Every iteration, it just goes right
back to the first record. Put the .MoveFirst before the Do While statement.


:
Great that worked...But after all the last record is deleted it says
that it can't go to the current record. Any way of stopping this?
Thank you for your help...it is appreciated.
DS
 
K

Klatuu

Your loop logic is incorrect. You will not have both EOF and BOF True at the
same time. Below is a little clean up that will help


blnLocationBar = IIf(Me.Location = Bar,True, False)
If Forms!Sales.SalesDetails.Form!Text127 = 0 Then
With Forms!Sales.SalesDetails.Form.Recordset
Do While Not .EOF
.MoveFirst
.Edit
!SDInclusive = blnLocationBar
!SDTaxed = Not blnLocationBar
.Update
.MoveNext
Loop
End With
End If
DoCmd.GoToRecord , , acLast
End Sub
 
D

DS

Klatuu said:
Your loop logic is incorrect. You will not have both EOF and BOF True at the
same time. Below is a little clean up that will help


blnLocationBar = IIf(Me.Location = Bar,True, False)
If Forms!Sales.SalesDetails.Form!Text127 = 0 Then
With Forms!Sales.SalesDetails.Form.Recordset
Do While Not .EOF
.MoveFirst
.Edit
!SDInclusive = blnLocationBar
!SDTaxed = Not blnLocationBar
.Update
.MoveNext
Loop
End With
End If
DoCmd.GoToRecord , , acLast
End Sub


:
Hi Thanks for the input...
I tried you code and it just kept running....
This works except if there are no records in SalesDetails
or if I delete the last record I get an Error message saying can't go to
current record, any idea how to remedy this? Once again, Thank You.
DS

If Me.Location = "Bar" Then
With Forms!Sales.SalesDetails.Form.Recordset
If Me.Text127 = 0 Then
.MoveFirst
Do While .EOF = False And .BOF = False
.Edit
!SDInclusive = True
!SDTaxed = False
.Update
.MoveNext
Loop
End If
End With
Else

With Forms!Sales.SalesDetails.Form.Recordset
If Me.Text127 = 0 Then
.MoveFirst
Do While .EOF = False And .BOF = False
.Edit
!SDInclusive = False
!SDTaxed = True
.Update
.MoveNext
Loop
End If
End With
End If
DoCmd.GoToRecord , , acLast
End Sub
 
K

Klatuu

Not too surprised. I had noticed there was not check to see if there are
rows to process. Notice the addition below:

blnLocationBar = IIf(Me.Location = Bar,True, False)
If Forms!Sales.SalesDetails.Form!Text127 = 0 Then
If Forms!Sales.SalesDetails.Form.Recordset .RecordCount <> 0 Then
With Forms!Sales.SalesDetails.Form.Recordset
Do While Not .EOF
.MoveFirst
.Edit
!SDInclusive = blnLocationBar
!SDTaxed = Not blnLocationBar
.Update
.MoveNext
Loop
End With
End If
DoCmd.GoToRecord , , acLast
End If
End Sub

The other part about deleting a record I am not sure. When are you deleting
the record? The only thing I can think of (and this may not be totally
correct, but give it a try) is that when you delete a record, I think it
tries to make the next record the current record, so it may be causing the
problem. Just for grins, try a MovePrevious.
 
D

DS

Klatuu said:
Not too surprised. I had noticed there was not check to see if there are
rows to process. Notice the addition below:

blnLocationBar = IIf(Me.Location = Bar,True, False)
If Forms!Sales.SalesDetails.Form!Text127 = 0 Then
If Forms!Sales.SalesDetails.Form.Recordset .RecordCount <> 0 Then
With Forms!Sales.SalesDetails.Form.Recordset
Do While Not .EOF
.MoveFirst
.Edit
!SDInclusive = blnLocationBar
!SDTaxed = Not blnLocationBar
.Update
.MoveNext
Loop
End With
End If
DoCmd.GoToRecord , , acLast
End If
End Sub

The other part about deleting a record I am not sure. When are you deleting
the record? The only thing I can think of (and this may not be totally
correct, but give it a try) is that when you delete a record, I think it
tries to make the next record the current record, so it may be causing the
problem. Just for grins, try a MovePrevious.

:
Thanks, I'll give it a try.
DS
 
S

SteveS

Klatuu said:
Not too surprised. I had noticed there was not check to see if there are
rows to process. Notice the addition below:

blnLocationBar = IIf(Me.Location = Bar,True, False)
If Forms!Sales.SalesDetails.Form!Text127 = 0 Then
If Forms!Sales.SalesDetails.Form.Recordset .RecordCount <> 0 Then
With Forms!Sales.SalesDetails.Form.Recordset
Do While Not .EOF
.MoveFirst
.Edit
!SDInclusive = blnLocationBar
!SDTaxed = Not blnLocationBar
.Update
.MoveNext
Loop
End With
End If
DoCmd.GoToRecord , , acLast
End If
End Sub

The other part about deleting a record I am not sure. When are you deleting
the record? The only thing I can think of (and this may not be totally
correct, but give it a try) is that when you delete a record, I think it
tries to make the next record the current record, so it may be causing the
problem. Just for grins, try a MovePrevious.

:)
Small correction..As Mike pointed out earlier, the .MoveFirst needs to be
outside the Do..Loop

blnLocationBar = IIf(Me.Location = Bar,True, False)
If Forms!Sales.SalesDetails.Form!Text127 = 0 Then
If Forms!Sales.SalesDetails.Form.Recordset .RecordCount <> 0 Then
With Forms!Sales.SalesDetails.Form.Recordset
.MoveFirst '<<<<<<<<
Do While Not .EOF
.Edit
!SDInclusive = blnLocationBar
!SDTaxed = Not blnLocationBar
.Update
.MoveNext
Loop
End With
End If
DoCmd.GoToRecord , , acLast
End If
End Sub
 

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

Top