|
Sub 提取生产计划明细()
Dim Conn As ADODB.Connection
Set Conn = LinkDB
Dim Rs As New ADODB.Recordset
SQL = "select * from 进度计划总表 where 日期 >= #" & 起始日期 & "# and 日期 <= #" & 终止日期 & "# order by 日期"
Rs.Open SQL, Conn, 1, 3
If Rs.RecordCount = 0 Then
MsgBox "当前周期尚未无生产计划安排明细,请在下表依次输入相关信息后再导入生产计划总表!"
Conn.Close: Set Conn = Nothing: Set Rs = Nothing
Exit Sub
Else
Dim i%, n%
n = 5
[a6:k5000].ClearContents
For i = 1 To Val(Rs.RecordCount)
n = n + 1
Cells(n, 1) = Rs.Fields("日期")
Cells(n, 2) = Rs.Fields("款号")
Cells(n, 3) = Rs.Fields("工序名称")
Cells(n, 4) = Rs.Fields("计划人数")
Cells(n, 5) = Rs.Fields("计划产量")
Cells(n, 6) = Rs.Fields("实际人数")
Cells(n, 7) = Rs.Fields("实际产量")
Cells(n, 8) = Rs.Fields("达成率")
'-------下面这段是想走到这一步时统计当前记录中工序名称实际产量总和,结果出错了!学习中,请高手莫骂
工序 = Rs.Fields("工序名称")
SQL = "select sum(实际产量) as 已完成量 from 进度计划总表 where 实际产量>0 and 工序名称='" & 工序 & "'"
Set Rs = Conn.Execute(SQL)
已完成量 = IIf(IsNull(Rs("已完成量")), "待统计", Int(Rs("已完成量")))
Cells(n, 9) = 已完成量
‘-------写入的第一条记录是正确的,但第二条就报错了!
Cells(n, 10) = Rs.Fields("总数量")
Cells(n, 11) = Rs.Fields("备注")
Rs.MoveNext
Next
End If
Conn.Close: Set Conn = Nothing: Set Rs = Nothing
End Sub
|
|