Bound Control, Bound Object Frame Control, Check Box Control, Combo Box Control, List Box Control, Option Button Control, Option Group Control, Text Box Control, Toggle Button Control.
You can use the OldValue property to determine the unedited value of a bound control.
The OldValue property contains the unedited data from a bound control and is read-only in all views.
You can access this property only in a macro or Visual Basic.
The OldValue property can be assigned to a variable using the following syntax.
OriginalValue = Forms!Customers!AmountPaid.OldValue
Microsoft Access uses the OldValue property to retrieve the value of a control as it exists in the underlying record. When you edit a bound control on a form, your changes aren’t saved until you move to another record. The OldValue property contains the unedited version of the underlying data.
You can provide your own undo capability by assigning the OldValue property setting to a control. The following example shows how you can restore the unedited contents of the control Date.
Forms!Orders!Date = Forms!Orders!Date.OldValue
If the control hasn’t been edited, this example has no effect. When you move to another record, the database is updated, so the current value and the OldValue property will be the same.
The OldValue property setting has the same data type as the field to which the control is bound.
ControlSource Property, Value Property.
The following example checks to determine if new data entered in a field is within 10 percent of the value of the original data. If the change is greater than 10 percent, the OldValue property is used to restore the original value.
Sub Validate_Field() Dim curNewValue As Currency, curOriginalValue As Currency Dim curChange As Currency, strMsg As String curNewValue = Forms!Employees!RaiseAmount curOriginalValue = Forms!Employees!RaiseAmount.OldValue curChange = Abs(curNewValue - curOriginalValue) If curChange > (curOriginalValue * .1) Then strMsg = "Change is more than 10 percent of original." strMsg = strMsg & vbCrLf & "Restoring original value." MsgBox strMsg, vbExclamation, "Invalid change" Forms!Employees!RaiseAmount = curOriginalValue End IfSub