Hi all,
I am entering new territory and could do with some help!
Main form - frm_NewOrder
Subform1 - frm_OrderPart
Subform2 (also nested in main form) - frm_Deliveries
The Main Form has a button btn_CompleteOrder. In the OnClick event I have the following:
This works perfectly when OrderPartID = 9. What I want to do is repeat this code for all OrderParts with an OrderID equal to the main form's ID. There may be 1 order part or 100. I guess I need to use a loop of some description but I've never done it before and can't get my head around how!!
Any help much appreciated.
Jason
I am entering new territory and could do with some help!
Main form - frm_NewOrder
Subform1 - frm_OrderPart
Subform2 (also nested in main form) - frm_Deliveries
The Main Form has a button btn_CompleteOrder. In the OnClick event I have the following:
Code:
Private Sub btn_CompleteOrder_Click()
[COLOR=green]'Create variables[/color]
Dim vOrderPartID As Integer
Dim vOrderID As Integer
Dim vDeliveredSoFar As Long
Dim vTotalToDeliver As Long
Dim vStillToDeliver As Long
vOrderID = Me.ID
[COLOR=green]'Set current OrderPartID[/color]
vOrderPartID = 9
[COLOR=green]'Check if any more deliveries are needed[/color]
vDeliveredSoFar = Nz(DSum("Quantity", "tbl_Deliveries", "OrderPartID = " & vOrderPartID), 0)
vTotalToDeliver = Nz(DSum("Quantity", "tbl_OrderPart", "ID = " & vOrderPartID), 0)
If vDeliveredSoFar = vTotalToDeliver Then GoTo NoMoreDeliveries Else GoTo AddDelivery
AddDelivery:
[COLOR=green]'Create new deliveries for all remaining quantities of OrderParts[/color]
vStillToDeliver = vTotalToDeliver - vDeliveredSoFar
DoCmd.RunSQL "INSERT INTO tbl_Deliveries (OrderPartID, DeliveryDate_Scheduled, Quantity, DeliveryDate_Delivered, OrderID, User) Values (" & vOrderPartID & ", Date(), " & vStillToDeliver & ", Date(), " & vOrderID & ", 'USER')"
DoCmd.RunCommand acCmdSaveRecord
Me.frm_Deliveries.Requery
NoMoreDeliveries:
End Sub
This works perfectly when OrderPartID = 9. What I want to do is repeat this code for all OrderParts with an OrderID equal to the main form's ID. There may be 1 order part or 100. I guess I need to use a loop of some description but I've never done it before and can't get my head around how!!
Any help much appreciated.
Jason