|
如果在表单中输入,还可以做错误提示:
一出现错误就用自已的错误处理:如下:
Private Sub ActiveX控件50_buttonclick(ByVal button As Object)
Select Case button.Key
Case "cmd_pass" '批核
On Error GoTo Err_pass
Dim Msg As String
Msg = MsgBox("您是否要批核这张单据?", vbInformation + vbYesNo, title:="批核提示")
If Msg = vbYes Then
'用ADO进行批核
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim rs2 As ADODB.Recordset
Dim rs3 As ADODB.Recordset
Set cn = CurrentProject.Connection
Set rs = New ADODB.Recordset
Set rs2 = New ADODB.Recordset
Set rs3 = New ADODB.Recordset
cn.BeginTrans
rs.Open "select 单据索引,项目编码,数量 from tbl_stk_单据细节 where 单据索引='" & Me.单据索引 & "'", cn, adOpenKeyset, adLockPessimistic
For a = 1 To rs.RecordCount
Select Case Me.录入仓库
Case "ME"
rs2.Open "select 项目编码,年 from tbl_stk_五金结存 where 项目编码='" & rs("项目编码") & "' and 年='" & Format(Me.交易日期, "yyyy") & "'", cn, adOpenKeyset, adLockPessimistic
rs3.Open "select 项目编码,五金结存,五金修理 from tbl_项目编码 where 项目编码='" & rs("项目编码") & "'", cn, adOpenKeyset, adLockPessimistic
If rs2.RecordCount = 0 Then
rs2.addnew
rs2("项目编码") = rs("项目编码")
rs2("年") = Format(Me.交易日期, "yyyy")
rs2.Update
End If
rs3("五金结存") = IIf(Me.交易编号 = "Fin" Or Me.交易编号 = "Ftin" Or Me.交易编号 = "In" Or Me.交易编号 = "Tin", rs3("五金结存") + rs("数量"), rs3("五金结存") - rs("数量"))
rs3.Update
rs2.close
rs3.close
rs.MoveNext Case "SE"
rs2.Open "select 项目编码,年 from tbl_stk_半成品结存 where 项目编码='" & rs("项目编码") & "' and 年='" & Format(Me.交易日期, "yyyy") & "'", cn, adOpenKeyset, adLockPessimistic
If rs2.RecordCount = 0 Then
rs2.addnew
rs2("项目编码") = rs("项目编码")
rs2("年") = Format(Me.交易日期, "yyyy")
rs2.Update
End If
rs3.Open "select 项目编码,半成品结存 from tbl_项目编码 where 项目编码='" & rs("项目编码") & "'", cn, adOpenKeyset, adLockPessimistic
rs3("半成品结存") = IIf(Me.交易编号 = "Fin" Or Me.交易编号 = "Ftin" Or Me.交易编号 = "In" Or Me.交易编号 = "Tin", rs3("半成品结存") + rs("数量"), rs3("半成品结存") - rs("数量"))
rs3.Update
rs2.close
rs3.close
rs.MoveNext
End Select
Next
If MsgBox("您是否储存批核后所作的修改吗?", vbInformation + vbYesNo, title:="储存批核") = vbYes Then
cn.CommitTrans
'Me.是否批核 = 1
MsgBox "单据已成功批核过帐,谢谢!!!", vbInformation, title:="批核成功"
Else
cn.RollbackTrans
Exit Sub
End If
ElseIf Msg = vbNo Then
Exit Sub
End If
GoTo Exit_toolbar
Err_pass:
MsgBox "无法预测的错误,发现这个问题请找设计人员解决。", vbInformation, title:="批核错误" ‘这一段就是自已的错误处理
End Select
Exit_toolbar:
End Sub
|
|