NavigationButton.OldValue 属性 (Access)

使用 OldValue 属性确定绑定控件的未编辑值。 只读变体

语法

表达式OldValue

表达 一个代表 NavigationButton 对象的变量。

备注

OldValue 属性包含的是绑定控件中未编辑的数据,则在所有视图中以只读的。

Microsoft Access 使用 OldValue 属性来存储绑定控件的原始值。 编辑窗体上的绑定的控件时,才能移动到另一个记录时保存所做的更改。 OldValue 属性包含的基础数据的未编辑的版本。

您可以通过为控件指定 OldValue 属性设置提供恢复数据的功能。 以下示例演示如何撤消对窗体上的文本框控件的任何更改。

Private Sub btnUndo_Click() 
 
 Dim ctlTextbox As Control 
 
 For Each ctlTextbox in Me.Controls 
 If ctlTextbox.ControlType = acTextBox Then 
 ctlTextbox.Value = ctl.OldValue 
 End If 
 Next ctlTextbox 
 
End Sub

如果控件尚未编辑,该代码不起作用。 当移动到其他记录时,记录源将更新,这样当前值和 OldValue 属性是相同的。

OldValue 属性设置具有相同的数据类型作为该控件所绑定到的字段。

示例

下面的示例检查以确定在字段中输入的新数据是否在原始数据值的 10%。 如果更改为大于 10%, OldValue 属性用于还原为原始值。 可以从包含要验证的数据的控件的 BeforeUpdate 事件调用此过程。

Public Sub Validate_Field() 
 
 Dim curNewValue As Currency 
 Dim curOriginalValue As Currency 
 Dim curChange As Currency 
 Dim strMsg As String 
 
 curNewValue = Forms!Products!UnitPrice 
 curOriginalValue = Forms!Products!UnitPrice.OldValue 
 curChange = Abs(curNewValue - curOriginalValue) 
 
 If curChange > (curOriginalValue * .1) Then 
 strMsg = "Change is more than 10% of original unit price." _ 
 & "Restoring original unit price." 
 MsgBox strMsg, vbExclamation, "Invalid change." 
 Forms!Products!UnitPrice = curOriginalValue 
 End If 
 
End Sub

支持和反馈

有关于 Office VBA 或本文档的疑问或反馈? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。