项目有两个表,"库存运维"和"出入库记录",两表都有同一名称列“配件名称”,两表之间没有设关联。
现在通过在库存运维表中的DataColChanged事件中写代码实现 滚动显示最近30天的出库数量。
我每次修改日期测试的时候就会提示错误“Exception has been thrown by the target of an invocation.”
求高手帮我看看为什么会这样?
以下是库存运维表DataColChanged中的代码:
If e.DataCol.Name = "配件名称" Then
e.DataRow("出库总量") = DataTables("出入库记录").Compute("Sum(出库)","[配件名称] = '" & e.NewValue & "'")
e.DataRow("最近30天出库数量") = DataTables("出入库记录").Compute("Sum(出库)","[配件名称] = '" & e.NewValue & "' And [日期]<=#" & Date.Today & "# And [日期]>#" & Date.Today.AddDays(-31) & "#")
End
If
为了使每次出入库记录表中数据有变化都触发库存运维表的DataColChanged事件,我又在出入库记录表的
DataColChanged事件下了代码入下:
If e.DataCol.Name = "出库" Then
Dim pr As DataRow
pr =
DataTables("库存运维").Find(" 配件名称= '" & e.DataRow("配件名称") & "'")
If pr IsNot Nothing Then
pr(
"出库总量")= pr("出库总量") + e.NewValue - e.OldValue
End If
ElseIf
e.DataCol.Name="配件名称" Or "日期"
If e.NewValue<>e.OldValue
DataTables("库存运维").DataCols("配件名称").RaiseDataColChanged()
End If
End
If
我其实也试着在MaintableChanged事件里面写RaiseDataColChanged(),测试下来没问题,想知道为什么以上的代码就有问题