【发布时间】:2016-02-04 13:41:46
【问题描述】:
我在报表上有七个文本框,这些文本框由 DSum 使用 VBA 填充。只有在进行压缩/修复或关闭数据库并重新打开数据库后,才会显示正确的值。
我尝试在关闭时关闭 Compact,看看是否有影响,但没有。
我已经到处刷新和重新查询,但仍然没有运气。
我已经调整了 txtLTL 的控制源,以便它寻找一个简单的值而不是更长的查询,什么都没有。
我手动设置了控制源,什么都没有。在 VBA 中执行此操作的原因是更容易在我们所有的数据库中进行复制。
代码如下:
Me.txtUPS.ControlSource = "=DSum(""CCur(Shipping)"",""Orders"",""ShipMethod Like 'UPS%'"")"
Me.txtUSPS.ControlSource = "=DSum(""Shipping"",""Orders"",""ShipMethod Like 'USPS%'"")"
Me.txtFedEx.ControlSource = "=DSum(""Shipping"",""Orders"",""ShipMethod Like 'Fed%'"")"
Me.txtDHL.ControlSource = "=DSum(""Shipping"",""Orders"",""ShipMethod Like 'DHL%'"")"
Me.txtLTL.ControlSource = "=DSum(""Shipping"",""Orders"",""shipmethod not like 'UPS%' and shipmethod not like 'USPS%' and shipmethod not like 'fed%' and shipmethod not like 'DHL%' and shipmethod not like 'CPU' and shipmethod not like 'Courier' and shipping > 0"")"
Me.txtCourier.ControlSource = "=DSum(""Shipping"",""Orders"",""ShipMethod Like 'Courier'"")"
Me.txtCPU.ControlSource = "=DSum(""Shipping"",""Orders"",""ShipMethod Like 'CPU'"")"
奇怪的是 - txtLTL 将在代码第一次运行时填充所有内容,但在关闭并重新打开后,将填充正确的文本框。
我现在完全不知所措了。
【问题讨论】:
-
为什么要在运行时通过 VBA 设置 ControlSources(而不是在报表设计中)? -- 该代码位于哪个事件中?
-
原帖已更新。在 VBA 中这样做的原因是更容易在我们所有的数据库中进行复制。它是从开放状态开始的。