我有一个带有文本框的Access表单,该表单用作表达式,因为它是控制源来计算要显示的值。虽然以下表达式在Access 2003中正常工作,但它不会自动显示在Access 2007中。仅当我单击该字段时,才会显示该值。它的作用是根据表单上的其他字段检查数据库中的值。如果为NULL,则该字段显示“N / A”。如果它不是NULL,则显示在数据库中找到的值。
有谁知道我可能做错了什么?
=IIf
(
IsNull( DLookUp("SomeField","SomeTable","SomeField = Forms!frm_FormName!cboSomeCombobox")),
"N/A",
LookUp("SomeField","SomeTable","SomeField = Forms!frm_FormName!cboSomeCombobox")
)
答案 0 :(得分:2)
2007 Microsoft Office套件Service Pack 1在Access 2007中修复的问题
On a Windows Vista-based computer, fields that are bound to time-intensive
expressions are blank in Access 2007
Fields that are bound to time-intensive expressions are blank in Access 2007.
These fields are empty until you click the text box or until you click anything
outside of Access 2007 if the following conditions are true:
The Control Source property of a text box uses the DLookup() function.
The query that is called by the DLookup() function references a control on
a form.
答案 1 :(得分:0)
我以前碰到过这个。以前,在使用Google搜索后,我在几个不同的Access VBA论坛上都提到了它,但现在我找不到这些匹配。
今天我已经摆弄了几个小时。我在各种事件中尝试了各种代码位,但是众所周知,Report View
遇到的事件触发器比Print Preview
少得多。但是,我确实找到了一种解决方法,并针对此令人讨厌的错误找到了两个重要发现:
TextBox
不需要获得关注;只需访问.Value
属性就足以使其获得适当显示其内容所需的便利。因此,.SetFocus
方法不是必需的。Section_Paint
事件足以满足此目的。以下代码对我有用。当然,请更改节和控件名称以使其与您自己的报表中的名称相匹配。
正常警告:滚动报告时,这会导致系统上的屏幕闪烁。我确实尝试用Application.Echo
禁用屏幕更新,但这只会使闪烁更糟。似乎事件中添加的每一行代码,无论它是什么,都使闪烁变得更糟。似乎是时间问题:
Private Sub GrpGlacctFooter_Paint()
Dim DummyVar As Variant
'DummyVar can be reused for each control. We just need somewhere (anywhere) to
'stuff each .Value. Simply accessing .Value in any way is enough to trigger the
'TextBoxes to display their contents.
DummyVar = txtAcctSubtotalMessage.Value
DummyVar = txtAcctTotalSpent.Value
DummyVar = txtAcctRemainder.Value
End Sub