gokrip
05-27-2011, 01:27 PM
In the subrountine below, the table does not get updated unless I click on the chkSetup box twice. Both the first click and the second click the update code is processed evidenced by the msgbox "standard costing updated" triggering. Any Ideas?
Private Sub chkSetup_Click()
Const ConnectionString = "DSN=HKPEDATA;UID=;PWD="
'Dim ProdLot As String
Dim MatNum As String
Dim MoldNum As String
Dim PerfMach As String
Dim PricePerLb As Currency
Dim PartWtg As Single
Dim RunnerWt As Single
Dim NumCavs As Integer
Dim Yield As Single
Dim AnnualProdRuns As Integer
Dim RMLbsPerSetup As Integer
Dim AnnualQty As Long
Dim DLPercent As Single
Dim QAPercent As Single
Dim ActualCycle As Single
Dim Efficiency As Single
Dim SetupHrs As Single
Dim DeprFactor As Single
Dim UtilityFactor As Single
Dim AnnualMaintCost As Integer
Dim AddChargesEa As Currency
Dim ProdLot As String
Dim rst As New ADODB.Recordset
Dim con As New ADODB.Connection
Dim sql As String
On Error Resume Next
If [chkSetup] = False Then
Exit Sub
Else
Call con.Open(ConnectionString)
DoCmd.Hourglass True
shift1 = True
shift2 = True
shift3 = True
PricePerLb = DLookup("[price/lb]", "[material]", "[materialnum] = forms![frmProductionSchedule]![matnum]")
PartWtg = DLookup("[partwtg]", "[part number]", "[partnumber] = forms![frmProductionSchedule]![partnumber]")
RunnerWt = DLookup("[runnerwt]", "[tooling]", "[moldnum] = forms![frmProductionSchedule]![moldnum]")
NumCavs = DLookup("[# cav]", "[tooling]", "[moldnum] = forms![frmProductionSchedule]![moldnum]")
Yield = DLookup("[yield]", "[part number]", "[partnumber] = forms![frmProductionSchedule]![partnumber]")
AnnualProdRuns = DLookup("[annualprodruns]", "[part number]", "[partnumber] = forms![frmProductionSchedule]![partnumber]")
RMLbsPerSetup = DLookup("[rmlbspersetup]", "[tooling]", "[moldnum] = forms![frmProductionSchedule]![moldnum]")
AnnualQty = DLookup("[annualqty]", "[part number]", "[partnumber] = forms![frmProductionSchedule]![partnumber]")
DLPercent = DLookup("[dlpercent]", "[tooling]", "[moldnum] = forms![frmProductionSchedule]![moldnum]")
QAPercent = DLookup("[qapercent]", "[part number]", "[partnumber] = forms![frmProductionSchedule]![partnumber]")
ActualCycle = DLookup("[actual cycle]", "[tooling]", "[moldnum] = forms![frmProductionSchedule]![moldnum]")
Efficiency = DLookup("[efficiency]", "[part number]", "[partnumber] = forms![frmProductionSchedule]![partnumber]")
SetupHrs = DLookup("[setupcharge]", "[tooling]", "[moldnum] = forms![frmProductionSchedule]![moldnum]")
DeprFactor = DLookup("[deprfactor]", "[asset list]", "[assetnum] = forms![frmProductionSchedule]![perfmach]")
UtilityFactor = DLookup("[utilityfactor]", "[asset list]", "[assetnum] = forms![frmProductionSchedule]![perfmach]")
AnnualMaintCost = DLookup("[annualmaintcost]", "[tooling]", "[moldnum] = forms![frmProductionSchedule]![moldnum]")
AddChargesEa = DLookup("[addchargesea]", "[part number]", "[partnumber] = forms![frmProductionSchedule]![partnumber]")
rm = MldgRMCost(PricePerLb, PartWtg, RunnerWt, NumCavs, Yield, _
AnnualProdRuns, RMLbsPerSetup, AnnualQty)
dl = MldgDLCost(DLPercent, QAPercent, NumCavs, ActualCycle, Efficiency, _
Yield, SetupHrs, AnnualProdRuns, AnnualQty, 1)
mach = MldgMachCost(DeprFactor, UtilityFactor, NumCavs, ActualCycle, Efficiency, Yield, 1)
tool = AnnualMaintCost / AnnualQty
pack = Nz(DSum("[loprice]*[qtyper]", "[qryBomDetail]", _
"[usedonpartnum]=forms![frmProductionSchedule]![partnumber] and [pnclass] = '5'"), 0)
other = Nz([AddChargesEa], 0) + Nz(DSum("[loprice]*[qtyper]", "[qryBomDetail]", _
"[usedonpartnum]=forms![frmProductionSchedule]![partnumber] and [pnclass] <> '5' and [pnclass]<> '7'"), 0)
ProdLot = Forms![frmproductionschedule]![ProdLotID]
sql = "SELECT * FROM [tblProdLot] WHERE [ProdLotID] = " & ProdLot & ";"
If Me.Dirty Then
' MsgBox "turning dirty to false"
Me.Dirty = False
End If
Call rst.Open(sql, con, adOpenDynamic, adLockOptimistic)
rst("stdRMCost").Value = Nz(rm, 0)
rst("stdDLCost").Value = Nz(dl, 0)
rst("stdMachCost").Value = Nz(mach, 0)
rst("stdToolCost").Value = Nz(tool, 0)
rst("stdPackCost").Value = Nz(pack, 0)
rst("stdOtherCost").Value = Nz(other, 0)
rst.Update
rst.Close
con.Close
' MsgBox "prior to refresh"
Refresh
Set rst = Nothing
Set con = Nothing
DoCmd.Hourglass False
MsgBox "Standard costing updated."
End If
End Sub
Private Sub chkSetup_Click()
Const ConnectionString = "DSN=HKPEDATA;UID=;PWD="
'Dim ProdLot As String
Dim MatNum As String
Dim MoldNum As String
Dim PerfMach As String
Dim PricePerLb As Currency
Dim PartWtg As Single
Dim RunnerWt As Single
Dim NumCavs As Integer
Dim Yield As Single
Dim AnnualProdRuns As Integer
Dim RMLbsPerSetup As Integer
Dim AnnualQty As Long
Dim DLPercent As Single
Dim QAPercent As Single
Dim ActualCycle As Single
Dim Efficiency As Single
Dim SetupHrs As Single
Dim DeprFactor As Single
Dim UtilityFactor As Single
Dim AnnualMaintCost As Integer
Dim AddChargesEa As Currency
Dim ProdLot As String
Dim rst As New ADODB.Recordset
Dim con As New ADODB.Connection
Dim sql As String
On Error Resume Next
If [chkSetup] = False Then
Exit Sub
Else
Call con.Open(ConnectionString)
DoCmd.Hourglass True
shift1 = True
shift2 = True
shift3 = True
PricePerLb = DLookup("[price/lb]", "[material]", "[materialnum] = forms![frmProductionSchedule]![matnum]")
PartWtg = DLookup("[partwtg]", "[part number]", "[partnumber] = forms![frmProductionSchedule]![partnumber]")
RunnerWt = DLookup("[runnerwt]", "[tooling]", "[moldnum] = forms![frmProductionSchedule]![moldnum]")
NumCavs = DLookup("[# cav]", "[tooling]", "[moldnum] = forms![frmProductionSchedule]![moldnum]")
Yield = DLookup("[yield]", "[part number]", "[partnumber] = forms![frmProductionSchedule]![partnumber]")
AnnualProdRuns = DLookup("[annualprodruns]", "[part number]", "[partnumber] = forms![frmProductionSchedule]![partnumber]")
RMLbsPerSetup = DLookup("[rmlbspersetup]", "[tooling]", "[moldnum] = forms![frmProductionSchedule]![moldnum]")
AnnualQty = DLookup("[annualqty]", "[part number]", "[partnumber] = forms![frmProductionSchedule]![partnumber]")
DLPercent = DLookup("[dlpercent]", "[tooling]", "[moldnum] = forms![frmProductionSchedule]![moldnum]")
QAPercent = DLookup("[qapercent]", "[part number]", "[partnumber] = forms![frmProductionSchedule]![partnumber]")
ActualCycle = DLookup("[actual cycle]", "[tooling]", "[moldnum] = forms![frmProductionSchedule]![moldnum]")
Efficiency = DLookup("[efficiency]", "[part number]", "[partnumber] = forms![frmProductionSchedule]![partnumber]")
SetupHrs = DLookup("[setupcharge]", "[tooling]", "[moldnum] = forms![frmProductionSchedule]![moldnum]")
DeprFactor = DLookup("[deprfactor]", "[asset list]", "[assetnum] = forms![frmProductionSchedule]![perfmach]")
UtilityFactor = DLookup("[utilityfactor]", "[asset list]", "[assetnum] = forms![frmProductionSchedule]![perfmach]")
AnnualMaintCost = DLookup("[annualmaintcost]", "[tooling]", "[moldnum] = forms![frmProductionSchedule]![moldnum]")
AddChargesEa = DLookup("[addchargesea]", "[part number]", "[partnumber] = forms![frmProductionSchedule]![partnumber]")
rm = MldgRMCost(PricePerLb, PartWtg, RunnerWt, NumCavs, Yield, _
AnnualProdRuns, RMLbsPerSetup, AnnualQty)
dl = MldgDLCost(DLPercent, QAPercent, NumCavs, ActualCycle, Efficiency, _
Yield, SetupHrs, AnnualProdRuns, AnnualQty, 1)
mach = MldgMachCost(DeprFactor, UtilityFactor, NumCavs, ActualCycle, Efficiency, Yield, 1)
tool = AnnualMaintCost / AnnualQty
pack = Nz(DSum("[loprice]*[qtyper]", "[qryBomDetail]", _
"[usedonpartnum]=forms![frmProductionSchedule]![partnumber] and [pnclass] = '5'"), 0)
other = Nz([AddChargesEa], 0) + Nz(DSum("[loprice]*[qtyper]", "[qryBomDetail]", _
"[usedonpartnum]=forms![frmProductionSchedule]![partnumber] and [pnclass] <> '5' and [pnclass]<> '7'"), 0)
ProdLot = Forms![frmproductionschedule]![ProdLotID]
sql = "SELECT * FROM [tblProdLot] WHERE [ProdLotID] = " & ProdLot & ";"
If Me.Dirty Then
' MsgBox "turning dirty to false"
Me.Dirty = False
End If
Call rst.Open(sql, con, adOpenDynamic, adLockOptimistic)
rst("stdRMCost").Value = Nz(rm, 0)
rst("stdDLCost").Value = Nz(dl, 0)
rst("stdMachCost").Value = Nz(mach, 0)
rst("stdToolCost").Value = Nz(tool, 0)
rst("stdPackCost").Value = Nz(pack, 0)
rst("stdOtherCost").Value = Nz(other, 0)
rst.Update
rst.Close
con.Close
' MsgBox "prior to refresh"
Refresh
Set rst = Nothing
Set con = Nothing
DoCmd.Hourglass False
MsgBox "Standard costing updated."
End If
End Sub