R
Robert Meerwaldt
Hi,
I have an order form, with a continuous order detail subform. The order
detail subform has a field 'QuantityReceived' (that can be edited), to
reflect how much of an item has actually arrived in a certain order. When
the user edits the values of the received quantities, I want to adjust the
stocklevels in the table TbItems accordingly for each items in the order.
Now the updating is not the problem, I have figured that one out (the rsorg
in the code is a recordset snapshot of the records before we allow editing).
The problem I am facing is how to iterate through all the records in the
order detail subform. I have tried various things but have not come up with
a solution. The code below is as far as I have gotten. I thought of using
the For Each ... Next loop, but cannot get it to work, probably because of
my limited knowledge of the VBA syntax. I am originally an Oracle
programmer, and with PL/SQL I could write the code blindly ...
Any help would be highly appreciated!
Robert
SAMPLE CODE:
'Update the stocklevel in TbItems from the Quantity Received field if it has
changed
For Each {record} in {FrmOrderdetails}
If FrmOrderDetails!QuantityReceived <> rsorg!QuantityReceived Then
strSQL = "UPDATE TbItems " & _
"SET TbItems.Stock = TbItems.Stock + " &
Forms!FrmOrders!FrmOrderDetails.Form!QuantityReceived & " " & _
"WHERE TbItems.Item_ID = " &
Forms!FrmOrders!FrmOrderDetails.Form!Item_ID
CurrentDb.Execute strSQL, dbFailOnError
End If
Next
I have an order form, with a continuous order detail subform. The order
detail subform has a field 'QuantityReceived' (that can be edited), to
reflect how much of an item has actually arrived in a certain order. When
the user edits the values of the received quantities, I want to adjust the
stocklevels in the table TbItems accordingly for each items in the order.
Now the updating is not the problem, I have figured that one out (the rsorg
in the code is a recordset snapshot of the records before we allow editing).
The problem I am facing is how to iterate through all the records in the
order detail subform. I have tried various things but have not come up with
a solution. The code below is as far as I have gotten. I thought of using
the For Each ... Next loop, but cannot get it to work, probably because of
my limited knowledge of the VBA syntax. I am originally an Oracle
programmer, and with PL/SQL I could write the code blindly ...
Any help would be highly appreciated!
Robert
SAMPLE CODE:
'Update the stocklevel in TbItems from the Quantity Received field if it has
changed
For Each {record} in {FrmOrderdetails}
If FrmOrderDetails!QuantityReceived <> rsorg!QuantityReceived Then
strSQL = "UPDATE TbItems " & _
"SET TbItems.Stock = TbItems.Stock + " &
Forms!FrmOrders!FrmOrderDetails.Form!QuantityReceived & " " & _
"WHERE TbItems.Item_ID = " &
Forms!FrmOrders!FrmOrderDetails.Form!Item_ID
CurrentDb.Execute strSQL, dbFailOnError
End If
Next