我有一个需要循环并添加到另一个临时表的数据透视查询。透视查询是找到的不同状态的总和。状态为Early、Late和On-Time。根据用户选择的内容,并非所有状态都存在。所以当我运行以下命令时:
Set rs1 = CurrentDb.OpenRecordset("MyReceivingOnTimeDeliverySummary", dbOpenDynaset)
Set rs = CurrentDb.OpenRecordset("TRANSFORM Sum(recvqty) AS SumOfrecvqty " & _
"SELECT supname, Sum(recvqty) AS TotalReceivedQty " & _
"FROM MyReceivingOnTimeDeliveryDetail " & _
"GROUP BY supname " & _
"PIVOT Status", dbOpenDynaset)
If (rs.RecordCount <> 0) Then
rs.MoveFirst
Do While rs.EOF <> True
rs1.AddNew
rs1.Fields("[supname]").value = rs.Fields("[supname]").value
rs1.Fields("[TotalReceivedQty]").value = rs.Fields("[TotalReceivedQty]").value
rs1.Fields("[Early]").value = rs.Fields("[Early]").value
rs1.Fields("[Late]").value = rs.Fields("[Late]").value
rs1.Fields("[OnTime]").value = rs.Fields("[On-Time]").value
rs1.Update
rs.MoveNext
Loop
End If
如果其中一种状态不在查询结果中,那么我将在将该值添加到MyReceivingOnTimeDeliverySummary
表中时出现错误。
我如何测试每个状态,如果它们不存在则添加为 0?