【问题标题】:DSum for textbox on Report only shows up after closing or compact/repair报表上文本框的 DSum 仅在关闭或压缩/修复后显示
【发布时间】: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 中这样做的原因是更容易在我们所有的数据库中进行复制。它是从开放状态开始的。

标签: vba ms-access


【解决方案1】:

此类问题的解决方案(或者更确切地说是变通方法)可以是:

将Form.TimerInterval 设置为1

然后像这样添加Form.Timer事件过程:

Private Sub Form_Timer()
    Me.TimerInterval = 0  ' turn off timer!
    Me.Recalc  ' this should be the correct method
End Sub

使用Timer 而不是Open 或Load 可确保在表单完成加载之后执行重新计算。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-11
    • 2019-11-02
    • 1970-01-01
    • 1970-01-01
    • 2013-11-02
    • 1970-01-01
    相关资源
    最近更新 更多