473,385 Members | 1,875 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

OldValue function not working

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
1 1320
Killer42
8,435 Expert 8TB
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

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

Similar topics

5
by: amit kumar | last post by:
I am calling a function which returns pointer to a map. The declaration of the map is map<int,vectxyz*>. vectxyz is a vector containing pointer to a class xyz. For map<int,vectxyz*>* p1 In the...
39
by: Randell D. | last post by:
Folks, I'm sure this can be done legally, and not thru tricks of the trade - I hope someone can help. I'm writing a 'tool' (a function) which can be used generically in any of my projects. ...
1
by: Andi Plotsky | last post by:
I am running some code to validate the entry made into a form called NumberOfSamples. If validation fails, then I want to revert back to the old value. I keep getting an error msg that says: ...
0
by: Bob Darlington | last post by:
I'm using the following code, which is called from the BeforeUpdate event in a form based on 'Tenant Details', to check for changes or additions to a series of dates, and if changed, to edit...
5
by: Dugo | last post by:
In Access 2003, I have a form (continuous form view) with several text boxes. The text boxes are not bound to a table since the layout of the form differs greatly from the structure of the...
1
by: gazelle04 | last post by:
I have these on BeforeUpdate event of a control If Me.txtAddress.Value <> Me.txtAddress.OldValue Then Me.txtGenInfo_UpdatedOn = Now Me.txtGenInfo_UpdatedBy = fOSUserName ...
2
by: Keith Wilby | last post by:
In A2k3 is it possible to determine if the OldValue property for a check box exists using code? Thanks. Keith.
8
by: Avi | last post by:
Hi all, I'm using string Replace(string oldValue, string newValue) and would like it to replace only full words that matches oldValue and not when oldValue is a substring of a larger word. ...
1
by: Allen Browne | last post by:
Testing if the new value is different from the old one avoids giving the message in these cases: a) It's a new record (so there was no old value.) b) No customer was specified previously (so the...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.