|
本帖最后由 kennylee 于 2011-9-4 18:40 编辑
窗体结构是:forms![报价单]![报价明细]![成本明细]!
问题是:当选定并展开子窗体【成本明细】按计算结果是对的。但不展开时,计算结果是错误的。明明选定子窗体【报价明细】第二条记录,但指针在计算第一条。是否“Set rs = Form_成本明细.Form.Recordset”声明错误呢。多谢!
Private Sub 计算_Click()
On Error Resume Next
Dim CLCB As Double '材料成本
Dim SCCB As Double '生产成本
Dim XS As Double '销售比率
Dim GL As Double '管理比率
Dim LR As Double '利润比率
CLCB = 0
SCCB = 0
GL = 0
XS = 0
LR = 0
Dim rs As dao.Recordset
Set rs = Form_成本明细.Form.Recordset
'rs.Requery
If DCount("小计", "直接成本", "[编号]=forms![报价单]![报价明细]![编号]") <> 0 Then
DoCmd.OpenQuery "费用项目追加"
rs.Requery
GL = DLookup("单价", "成本明细", "[编号]=forms![报价单]![报价明细]![编号] and [项目]='C管理费用'") / 100
XS = DLookup("单价", "成本明细", "[编号]=forms![报价单]![报价明细]![编号] and [项目]='B销售费用'") / 100
LR = DLookup("单价", "成本明细", "[编号]=forms![报价单]![报价明细]![编号] and [项目]='D利润'") / 100
'Stop
rs.MoveFirst
Do Until rs.EOF
If Form_成本明细.[项目] Like "*" & "料" & "*" Then '材料成本
CLCB = CLCB + Nz(Form_成本明细.[小计])
ElseIf Form_成本明细.[项目] Like "*" & "工" & "*" Then '工序成本
Dim tjy, jcy, zyy As String
tjy = DLookup("调机员", "工序成本", "[设备名称]='" & Form_成本明细.明细 & "'") '调机员月新
jcy = DLookup("检查员", "工序成本", "[设备名称]='" & Form_成本明细.明细 & "'") '检查员月新
zyy = DLookup("作业员", "工序成本", "[设备名称]='" & Form_成本明细.明细 & "'") '作业员月新
Dim A, B, C, D, E, F As Double
A = Nz(DLookup("调机工时", "工序成本", "[设备名称]='" & Form_成本明细.明细 & "'")) '调机工时
B = Nz(DLookup("月薪", "人员工资", "[岗位]='" & tjy & "'")) / 22 / 8 '调机员时新
C = Nz(DLookup("月薪", "人员工资", "[岗位]='" & jcy & "'")) / 22 / 8 '检查员时新
D = Nz(DLookup("月薪", "人员工资", "[岗位]='" & zyy & "'")) / 22 / 8 '作业员时新
E = Nz(Forms![报价单]![报价明细]![数量]) / (Form_成本明细.速度_重量 * 60 * 0.85) + Nz(A) '总工时
F = Nz(DLookup("折旧期", "工序成本", "设备名称='" & Form_成本明细.明细 & "'"))
Form_成本明细.工时 = E
Form_成本明细.折旧费 = DLookup("单价", "工序成本", "设备名称='" & Form_成本明细.明细 & "'") / F / 2000 * E
Form_成本明细.电费 = DLookup("功率", "工序成本", "设备名称='" & Form_成本明细.明细 & "'") * 1.2 * E
Form_成本明细.人工费 = B * A + (B + C) * E * 0.1 + D * (E - A) '调机费=B*A,维护费=(B + C) * E * 0.1,手加工费=D * (E - A)
Form_成本明细.单价 = (Nz(Form_成本明细.人工费) + Nz(Form_成本明细.电费) + Nz(Form_成本明细.折旧费)) / E
Form_成本明细.小计 = (Nz(Form_成本明细.人工费) + Nz(Form_成本明细.电费) + Nz(Form_成本明细.折旧费)) / Forms![报价单]![报价明细]![数量]
ElseIf Form_成本明细.[项目] = "A制造费用" Then
Form_成本明细.[小计] = (DSum("小计", "直接成本", "[编号]=forms![报价单]![报价明细]![编号]") * Form_成本明细.单价 / 100) / (1 - Form_成本明细.单价 / 100)
SCCB = DSum("小计", "直接成本", "[编号]=forms![报价单]![报价明细]![编号]") + Form_成本明细.[小计] '生产成本
Forms![报价单]![报价明细]![含税单价] = (1.17 * SCCB - CLCB * 0.17 * 1.1) / (1.17 * (1 - GL - XS - LR) - 0.17 * 1.1)
ElseIf Form_成本明细.[项目] = "B销售费用" Then
Form_成本明细.[小计] = Form_成本明细.[单价] / 100 * Forms![报价单]![报价明细]![含税单价]
ElseIf Form_成本明细.[项目] = "C管理费用" Then
Form_成本明细.[小计] = Form_成本明细.[单价] / 100 * Forms![报价单]![报价明细]![含税单价]
ElseIf Form_成本明细.[项目] = "D利润" Then
Form_成本明细.[小计] = Form_成本明细.[单价] / 100 * Forms![报价单]![报价明细]![含税单价]
ElseIf Form_成本明细.[项目] = "E税费" Then
Form_成本明细.[小计] = (Forms![报价单]![报价明细]![含税单价] - CLCB) / 1.17 * 0.17 * 1.1
Forms![报价单]![报价明细]![不含税单价] = Forms![报价单]![报价明细]![含税单价] - Form_成本明细.[小计]
End If
rs.MoveNext
Loop
rs.Requery
'Forms![报价单]![报价明细].Requery
End If
End Sub
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
|