B
Brandon
Hello I am using this code below to take a total savings number, break it out
by percentages and populate the subform based on these values. However I get
an error for "Item not found in the collection" when it is running through
the .AddNew Function. Why does this happen?
Thanks for any assistance!
Brandon
Private Sub cmdSGACalc_Click()
On Error GoTo Err_cmdSGACalc_Click
Dim curSavingsByMonth As Currency
Dim intMonth As Integer
Dim x As Integer
Dim intDivisionID As Integer
Dim intLocationID As Integer
Dim curHistoricVolume As Currency
Dim curLowBidAmt As Currency
Dim curImplementedBidAmt As Currency
Dim intProjectID As Integer
Dim intProjectType As Integer
Dim intCurrencyID As Integer
Dim intLotNumber As Integer
Dim curDivisionPercent(1 To 4) As Currency
curDivisionPercent(1) = 0.254
'BI
curDivisionPercent(2) = 0.176
'PM
curDivisionPercent(3) = 0.35
'EPG
curDivisionPercent(4) = 0.22
'RSG
intDivisionID = 1
x = 1
intProjectID = Me!ProjectID.Value
intLotNumber = Me!LotNumber.Value
intLocationID = 52 'North America
curHistoricVolume = Me!SGAHistoricVolume.Value
curLowBidAmt = Me!SGALowBidAmt.Value
curImplementedBidAmt = Me!SGAImplementedBidAmt.Value
intProjectType = Me!SGAProjectTypeID.ItemData(1)
intCurrencyID = Me!SGACurrencyID.ItemData(1)
Me!sfrmLotBreakout.SetFocus
Me.sfrmLotBreakout.CostAvoidance.SetFocus
With Me!sfrmLotBreakout.Form.RecordsetClone
For x = 1 To 4
'calculate the monthly savings and add records
'to the subform Brandon Cheal 7/14/04
.AddNew
!ProjectTypeID = intProjectType
!CurrencyID = intCurrencyID
!LotNumber = intLotNumber
!DivisionID = intDivisionID
!LocationID = intLocationID
!HistoricVolume = curHistoricVolume *
curDivisionPercent(intDivisionID)
!LowBidAmt = curLowBidAmt *
curDivisionPercent(intDivisionID)
!ImplementedBidAmt = curImplementedBidAmt *
curDivisionPercent(intDivisionID)
!ProjectID = intProjectID
.Update
intDivisionID = intDivisionID + 1
Next x
End With
Exit_cmdSGACalc_Click:
Exit Sub
Err_cmdSGACalc_Click:
MsgBox Err.Description
Resume Exit_cmdSGACalc_Click
End Sub
by percentages and populate the subform based on these values. However I get
an error for "Item not found in the collection" when it is running through
the .AddNew Function. Why does this happen?
Thanks for any assistance!
Brandon
Private Sub cmdSGACalc_Click()
On Error GoTo Err_cmdSGACalc_Click
Dim curSavingsByMonth As Currency
Dim intMonth As Integer
Dim x As Integer
Dim intDivisionID As Integer
Dim intLocationID As Integer
Dim curHistoricVolume As Currency
Dim curLowBidAmt As Currency
Dim curImplementedBidAmt As Currency
Dim intProjectID As Integer
Dim intProjectType As Integer
Dim intCurrencyID As Integer
Dim intLotNumber As Integer
Dim curDivisionPercent(1 To 4) As Currency
curDivisionPercent(1) = 0.254
'BI
curDivisionPercent(2) = 0.176
'PM
curDivisionPercent(3) = 0.35
'EPG
curDivisionPercent(4) = 0.22
'RSG
intDivisionID = 1
x = 1
intProjectID = Me!ProjectID.Value
intLotNumber = Me!LotNumber.Value
intLocationID = 52 'North America
curHistoricVolume = Me!SGAHistoricVolume.Value
curLowBidAmt = Me!SGALowBidAmt.Value
curImplementedBidAmt = Me!SGAImplementedBidAmt.Value
intProjectType = Me!SGAProjectTypeID.ItemData(1)
intCurrencyID = Me!SGACurrencyID.ItemData(1)
Me!sfrmLotBreakout.SetFocus
Me.sfrmLotBreakout.CostAvoidance.SetFocus
With Me!sfrmLotBreakout.Form.RecordsetClone
For x = 1 To 4
'calculate the monthly savings and add records
'to the subform Brandon Cheal 7/14/04
.AddNew
!ProjectTypeID = intProjectType
!CurrencyID = intCurrencyID
!LotNumber = intLotNumber
!DivisionID = intDivisionID
!LocationID = intLocationID
!HistoricVolume = curHistoricVolume *
curDivisionPercent(intDivisionID)
!LowBidAmt = curLowBidAmt *
curDivisionPercent(intDivisionID)
!ImplementedBidAmt = curImplementedBidAmt *
curDivisionPercent(intDivisionID)
!ProjectID = intProjectID
.Update
intDivisionID = intDivisionID + 1
Next x
End With
Exit_cmdSGACalc_Click:
Exit Sub
Err_cmdSGACalc_Click:
MsgBox Err.Description
Resume Exit_cmdSGACalc_Click
End Sub