On
Error GoTo ErrorHandler
Dim strsql As
String
Dim cnn As ADODB.Connection
Dim rstTmp As DAO.Recordset
Dim blnTransBegin As Boolean
Set cnn = GetADOConnection()
'启动事务
cnn.BeginTrans
cnn.Execute " UPDATE tbl_Wip_Wo_Dep_Gold_Master SET Status= '"
& Me![Status] & "',RecId= '" & Me![RecId] &
"',RecTime= " & Format$(Me![RecTime], "\'yyyy-mm-dd
hh:nn:ss\'") _
& " WHERE GdCode='"
& GdCode & "'" '关闭记录集
Set rst = New ADODB.Recordset
strsql = "SELECT * FROM tbl_gold_in_Bom"
rst.Open strsql, cnn, adLockOptimistic, adLockOptimistic
Set rstTmp =
CurrentDb.OpenRecordset("Temp_tbl_Wip_Wo_Dep_Gold_Detail")
Do Until rstTmp.EOF
cnn.Execute " UPDATE dbo.tbl_gold_Hc" _
& " SET zl=
IsNull(dbo.tbl_gold_Hc.zl,0) + " & Nz(rstTmp!GrossWeight, 0) _
& " WHERE Hc =
'" & Me.ToDep & "'and cs='" & rstTmp!AlloyCode &
"'"
cnn.Execute " UPDATE dbo.tbl_gold_Hc" _
& " SET zl=
IsNull(dbo.tbl_gold_Hc.zl,0) -" & Nz(rstTmp!GrossWeight, 0) _
& " WHERE Hc =
'" & Me.FromDep & "'and cs='" & rstTmp!AlloyCode
& "'"
rstTmp.MoveNext
Loop
rstTmp.Close
cnn.CommitTrans '提交事务
MsgBox "数据已保存。", vbInformation, "提示"
DoCmd.Close acForm, Me.name
ErrorHandler: '错误处理程序
If Not cnn Is Nothing Then
If cnn.State = adStateOpen Then cnn.Close
End If
Set cnn = Nothing
If Err.Number <> 0 Then MsgBox
Err.Number & " " & Err.Description '提示