|
Sub 生成新表()
Dim conn As New ADODB.Connection
Set conn = CurrentProject.Connection
Dim RST As New ADODB.Recordset
Dim SQL As String
' Dim cat As New ADOX.Catalog
' Dim cmd As New ADODB.Command
Dim rst1 As New ADODB.Recordset
' cat.ActiveConnection = conn
SQL = "DELETE 查询结果.* FROM 查询结果"
DoCmd.RunSQL SQL
sq = 0
sclj = 0
xslj = 0
qmkc = 0
RST.Open "交叉表", conn, adOpenKeyset, adLockOptimistic
rst1.Open "查询结果", conn, adOpenKeyset, adLockOptimistic
Do While Not RST.EOF
If cpid = RST("产品ID") Then
If ldid = RST("年度ID") Then
sclj = sclj + Nz(RST("生产"))
xslj = xslj + Nz(RST("销售"))
kc = qq + sclj - xslj
Else
qq = kc
sclj = Nz(RST("生产"))
xslj = Nz(RST("销售"))
End If
Else
qq = RST("期初库存")
sclj = Nz(RST("生产"))
xslj = Nz(RST("销售"))
kc = qq + sclj - xslj
End If
rst1.AddNew
rst1("年度ID") = RST("年度ID")
rst1("月份ID") = RST("月份ID")
rst1("产品ID") = RST("产品ID")
rst1("生产") = RST("生产")
rst1("销售") = RST("销售")
rst1("前期") = qq
rst1("生产累计") = sclj
rst1("销售累计") = xslj
rst1("库存") = kc
rst1.Update
cpid = RST("产品ID")
ldid = RST("年度ID")
yfid = RST("月份ID")
RST.MoveNext
Loop
rst1.Update
End Sub
'先按相应的字段做一个“查询结果”表,其它字段请自己补齐 |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
|