By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,985 Members | 1,830 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,985 IT Pros & Developers. It's quick & easy.

OldValue function not working

P: 3
I am making a Cancel button to close a form without saving. I check for changes in each control and if it changed I want to restore it to the old value, I get an error saying I can't assign value to this object. Here is my code

Expand|Select|Wrap|Line Numbers
  1. Private Sub Cancel_Click()
  2.     'Check for changes
  3.     If Me.Dirty Then
  4.         Dim ctrl As Control
  5.         ' For each control.
  6.         For Each ctrl In Me.Controls
  7.             If ctrl.ControlType = acTextBox Then
  8.                 ' Restore Old Value.
  9.                 ctrl.Value = ctrl.OldValue
  10.             End If
  11.         Next ctrl
  12.         'Close form
  13.         DoCmd.Close acForm, "Best Effort Trade Ticket Edit", acSaveNo
  14.     Else
  15.         'Close form
  16.         DoCmd.Close acForm, "Best Effort Trade Ticket Edit", acSaveNo
  17.     End If
  18. End Sub
Jan 7 '08 #1
Share this Question
Share on Google+
1 Reply

Expert 5K+
P: 8,434
Based on the DoCmd, it looks as though you're working in MS Access. If so, try the form's Undo method.
Jan 10 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.