Reverting to a previous value - the OldValue Property

<< Click to Display Table of Contents >>

Navigation:  Forms  >

Reverting to a previous value - the OldValue Property

If someone changes a value in a field and that change has repercussions for other fields on the form, you may wish to use the OldValue property. Here is a sample and just to explain, CreditRequired is a Yes/No combo box

 

 

Private Sub CreditRequired_Click()

 

  Dim intYesNo As Integer

  If CreditRequired = False And CreditRequired.OldValue = True And Not IsNull(CreditRequestDate) Then

  

    intYesNo = MsgBox("Choose Y and the Credit details will be cleared", vbYesNo + vbDefaultButton2, "Remove Credit Details")

    If intYesNo = vbYes Then

      CreditRequestDate = Null

      CreditCode = Null

    Else

      'Reset the value back to the previous value and do nothing

      CreditRequired.Value = CreditRequired.OldValue

    End If

  End If