Hi,
I have the code below, that is required to calculate the cost of a part, based on the rollup of the component parts. I have the code attached to the subform On Current event, however it seems to be applying the RRP to all of the records currently showing in the subform of the main form, rather than just the current subform record.
When the record is first created I could apply this in the After Update of the Part number field, but this won't help when you are just viewing the form.
Is there an event you can use for loading a subform that will run the code against all the individual records for that linked main form? Does it need to be run from a main form event?
Thanks
I have the code below, that is required to calculate the cost of a part, based on the rollup of the component parts. I have the code attached to the subform On Current event, however it seems to be applying the RRP to all of the records currently showing in the subform of the main form, rather than just the current subform record.
When the record is first created I could apply this in the After Update of the Part number field, but this won't help when you are just viewing the form.
Is there an event you can use for loading a subform that will run the code against all the individual records for that linked main form? Does it need to be run from a main form event?
Code:
Private Sub Form_Current()
Dim TempOrderDate
Dim strSQL
Dim ParentPartNo
Dim OrderedPartNo
Dim TotalCost
Dim RRP
If Not (Form.NewRecord) Then
TempOrderDate = Forms![CustomerOrderF]![OrderDate]
ParentPartNumber = DLookup("PartNumber", "PartslistT", "ProductID=" & ProductID)
OrderedPartNo = Me.ID & "_" & ParentPartNumber
If TempOrderDate >= Date Then
strSQL = "SELECT Sum(Query1.TotalCost) AS SumOfTotalCost, Query1.OrderedPartNo" & _
" FROM Query1" & _
" GROUP BY Query1.OrderedPartNo" & _
" HAVING (((Query1.OrderedPartNo)='" & OrderedPartNo & "'))"
Debug.Print strSQL
Dim RecordSet
Set RecordSet = CurrentDb.OpenRecordset(strSQL)
TotalCost = RecordSet("SumOfTotalCost")
RecordSet.Close
RRP = TotalCost * 2.35 + 4.5
Me.PartSellPrice.ControlSource = "=" & RRP
End If
End If
End Sub