|
6#
楼主 |
发表于 2003-4-6 23:42:00
|
只看该作者
Option Compare Database
Option Explicit
Dim cn As Connection
Dim rs As New ADODB.Recordset
Dim sql As String
Private Sub 命令0_Click()
Dim ZRKSL, ZRKJE, ZCKSL, ZCKJE, CYJC As Single
Dim QCSL, QCJE, JQDJ, SYJCE As Single
Select Case 查询选项
Case 1
DoCmd.OpenQuery "货品当月入库查询"
Case 2
DoCmd.OpenQuery "货品当月出库查询"
Case 3
DoCmd.RunMacro "上月结存查询"
Set cn = CurrentProject.Connection
sql = "select * from 上月结存临时表 "
rs.Open sql, cn, 3, 3, 1
If rs.RecordCount > 0 Then
Do While Not rs.EOF
ZRKSL = Nz(DLookup("入库数量", "货品上月总入库查询", "货品编码='" & rs.Fields("货品编码") & "'"), 0)
ZCKSL = Nz(DLookup("出库数量", "货品上月总出库查询", "货品编码='" & rs.Fields("货品编码") & "'"), 0)
ZRKJE = Nz(DLookup("总额", "货品上月总入库查询", "货品编码='" & rs.Fields("货品编码") & "'"), 0)
ZCKJE = Nz(DLookup("总额", "货品上月总出库查询", "货品编码='" & rs.Fields("货品编码") & "'"), 0)
rs.Fields("结存时间") = Date
rs.Fields("当月入库") = DLookup("入库数量", "货品上月入库查询", "货品编码='" & rs.Fields("货品编码") & "'")
rs.Fields("当月出库") = DLookup("出库数量", "货品上月出库查询", "货品编码='" & rs.Fields("货品编码") & "'")
rs.Fields("结存数") = Nz(rs.Fields("期初数"), 0) + Nz(ZRKSL, 0) - Nz(ZCKSL, 0)
rs.Fields("上月结存额") = Nz(rs.Fields("期初金额"), 0) + Nz(ZRKJE, 0) - Nz(ZCKJE, 0)
rs.Update
rs.MoveNext
Loop
rs.Close
End If
DoCmd.RunMacro "结存查询"
sql = "select * from 结存临时表 "
rs.Open sql, cn, 3, 3, 1
If rs.RecordCount > 0 Then
Do While Not rs.EOF
ZRKSL = Nz(DLookup("入库数量", "货品总入库查询", "货品编码='" & rs.Fields("货品编码") & "'"), 0)
ZRKJE = Nz(DLookup("总额", "货品总入库查询", "货品编码='" & rs.Fields("货品编码") & "'"), 0)
ZCKSL = Nz(DLookup("出库数量", "货品总出库查询", "货品编码='" & rs.Fields("货品编码") & "'"), 0)
ZCKJE = Nz(DLookup("总额", "货品总出库查询", "货品编码='" & rs.Fields("货品编码") & "'"), 0)
CYJC = Nz(DLookup("结存数", "上月结存临时表", "货品编码='" & rs.Fields("货品编码") & "'"), 0)
QCSL = Nz(DLookup("期初数量", "货品信息", "货品编码='" & rs.Fields("货品编码") & "'"), 0)
QCJE = Nz(DLookup("期初金额", "货品信息", "货品编码='" & rs.Fields("货品编码") & "'"), 0)
If QCSL + ZRKSL - ZCKSL <> 0 Then
JQDJ = IIf((QCSL + ZRKSL - ZCKSL) = 0, 0, (QCJE + ZRKJE - ZCKJE) / (QCSL + ZRKSL - ZCKSL))
Else
JQDJ = 0
End If
SYJCE = Nz(DLookup("上月结存额", "上月结存临时表", "货品编码='" & rs.Fields("货品编码") & "'"), 0)
rs.Fields("结存时间") = Date
rs.Fields("单价") = JQDJ
rs.Fields("上月结存") = CYJC
rs.Fields("当月入库") = DLookup("入库数量", "货品当月入库查询", "货品编码='" & rs.Fields("货品编码") & "'")
rs.Fields("当月出库") = DLookup("出库数量", "货品当月出库查询", "货品编码='" & rs.Fields("货品编码") & "'")
rs.Fields("当月结存") = Nz(rs.Fields("期初数"), 0) + Nz(ZRKSL, 0) - Nz(ZCKSL, 0)
rs.Fields("当月结存额") = Nz(QCJE + ZRKJE - ZCKJE, 0)
rs.Fields("上月结存额") = Nz(SYJCE, 0)
rs.Fields("当月入库额") = Nz(ZRKJE, 0)
rs.Fields("当月出库额") = Nz(ZCKJE, 0)
rs.Update
rs.MoveNext
DoEvents
Loop
rs.Close
Set cn = Nothing
End If
DoCmd.OpenReport "结存统计表", acViewPreview
End Select
DoCmd.Maximize
End Sub
Private Sub 退同_Click()
On Error GoTo Err_退同_Cli |
|