本帖最后由 todaynew 于 2009-4-23 15:48 编辑 Private Sub 加权法() Dim rs1 As New ADODB.Recordset Dim sql1 As String Dim rs2 As New ADODB.Recordset Dim sql2 As String Dim 累计数量 As Single Dim 累计金额 As Single Dim 单价 As Single Dim i as Long sql1 = "select * from 发料查询 where format(日期,'yymm')='" & Me.月度.Value & "'and 物资ID=" & Me.物资ID.Value rs1.Open sql1, CurrentProject.Connection, adOpenKeyset, adLockOptimistic sql2 = "select * from 库存及收料查询 where format(日期,'yymm')='" & Me.月度.Value & "'and 物资ID=" & Me.物资ID.Value rs2.Open sql2, CurrentProject.Connection, adOpenKeyset, adLockOptimistic 累计数量 = 0 累计金额 = 0 For i = 1 To rs2.RecordCount 累计数量 = 累计数量 + rs2("数量") 累计金额 = 累计金额 + rs2("金额") rs2.MoveNext Next 单价 = Round(累计金额 / 累计数量, 2) For i = 1 To rs1.RecordCount rs1("单价") = 单价 rs1("金额") = rs1("数量") * rs1("单价") rs1.Update rs1.MoveNext Next Me.收发子窗体.Form.Requery rs1.Close rs2.Close End Sub |
欢迎光临 Office中国论坛/Access中国论坛 (http://www.office-cn.net/) | Powered by Discuz! X3.3 |