Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cancel Button 1

Status
Not open for further replies.

EuanPirie

Programmer
Apr 15, 1999
66
0
0
GB
Am I being silly, but all I want to do is close a form, without saving the data. I have coded it as follows:<br>
<br>
Docmd.close , , acSaveNo<br>
<br>
but it still saves the data. Am I right in thinking that the data is added to the table as it is entered? If so, do I have to delete the data rather than cancel closing the form? Help, before I go bonkers!<br>
<br>
Euan
 
If the form is bound to the table the data is saved when you close the form, as it is when you navigate to a new record.<br>
In your code for the cancel button before the close command write the following:<br>
Me.Undo<br>
This will revert the fields to their original values.
 
This worked very well. However, I have now complicated things slightly. I have a form which controls data in a subform. It only holds a user ID, which is the control for the subform. The subform is a datasheet. If I edit data on the subform, and do not wish to save the changes, I want to be able to press the cancel button.<br>
<br>
I have tried specifying the form as a variable, using<br>
<br>
Dim frm As Form<br>
Set frm=Me!testsubform.Form<br>
Me.Undo<br>
Docmd.close<br>
<br>
However, while it does close the form, it does not make the undo changes. Am I on the right train of thought?
 
Put a cancel button on the subform?<br>
Or<br>
Instead of me.undo use [Forms]![subformname].undo. I have not checked this out but Me provides a way to refer to the specific instance of the class where the code is executing. Me in this case is refering to the main form so try using the actual name of the subform
 
When I tried this, it appears that it thinks the subform is not open or does not exist? It claims there may be a problem in the code. Any more ideas? I tried specifying the form, and this is were I get the problem.
 
I don't know if this is the best way to do it, and it certainly could cause problems if you are not careful, but you could use transactions on the workspace.<br>
<br>
The code would probably be something like this:<br>
<br>
In Form_Open, add the line<br>
<br>
call DBEngine.Workspaces(0).BeginTrans<br>
<br>
<br>
The next bit is potentially more complicated, as the user can, I assume, close the form using either an OK button, a Cancel button, or by clicking the form. What you have to do is work out where to put code so that one (and only one) of the following lines is executed when the form is closed:<br>
<br>
To cancel -<br>
call DBEngine.Workspaces(0).Rollback<br>
<br>
To save - <br>
call DBEngine.Workspaces(0).CommitTrans<br>
<br>
Once you have begun a transaction, you must ensure that you either commit it or roll it back, or you could get into trouble at a later stage<br>
<br>
Hope this helps<br>
<br>
Jonathan<br>
<br>
<br>

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top