OldValue 属性
OldValue 仅适用于绑定字段。 documentation 说:
OldValue 属性包含来自绑定控件的未编辑数据,并且在所有视图中都是只读的。
如果您需要跟踪未绑定控件的旧值,您可以通过代码手动完成:例如,您可以使用表单的 Current 或 Load 事件或组合框的 BeforeUpdate 事件将初始值加载到表单的 VBA 模块中定义的变量中。
一种(可能)更好的方法
您不需要维护一个专门的布尔列来确定该字段是否显示在另一个组合中。
让我们用一个具体的例子:
假设您的 Form1 上有 3 个组合框:Combo1、Combo2、Combo3。
我想显示每个国家的列表,并从列表中排除我已经在其他组合框中选择的国家。
将Combo1 的RowSource 设置为:
SELECT Country.ID,
Country.CountryName
FROM Country
WHERE (Country.ID Not In ([Forms]![Form1]![Combo2],
[Forms]![Form1]![Combo3]))
ORDER BY Country.[CountryName];
将Combo2 的RowSource 设置为:
SELECT Country.ID,
Country.CountryName
FROM Country
WHERE (Country.ID Not In ([Forms]![Form1]![Combo1],
[Forms]![Form1]![Combo3]))
ORDER BY Country.[CountryName];
将Combo3 的RowSource 设置为:
SELECT Country.ID,
Country.CountryName
FROM Country
WHERE (Country.ID Not In ([Forms]![Form1]![Combo1],
[Forms]![Form1]![Combo2]))
ORDER BY Country.[CountryName];
然后为每个组合框设置 GotFocus 事件以根据需要重新查询其内容:
Private Sub Combo1_GotFocus()
Combo1.Requery
End Sub
Private Sub Combo2_GotFocus()
Combo2.Requery
End Sub
Private Sub Combo3_GotFocus()
Combo3.Requery
End Sub