Link to home
Start Free TrialLog in
Avatar of kenabbott
kenabbottFlag for United Kingdom of Great Britain and Northern Ireland

asked on

MS Access VBA Undo on a sub form

Hi

I have a form with a Cancel button which if clicked undoes any changes to the form by using me.undo which works without problem.

However the form also has a sub form which I also want any changes to be undone when the cancel button on the main form is clicked.  What syntax would I use for this as all attempts so far have failed

many thanks
Avatar of danishani
danishani
Flag of United States of America image

ASKER CERTIFIED SOLUTION
Avatar of Jim Dettman (EE MVE)
Jim Dettman (EE MVE)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of kenabbott

ASKER

Many thanks - I think I'll opt for #2
Actually, I should have mentioned a third as well and that is the "unbound" approach; you use all un-bound controls on the form and controll all the CRUD (Create, Read, Update, Delete) operations in code either with temp tables or SQL on the fly.

 Most don't take that approach though because if your going to go that far, you might as well use something other then Access.

JimD.
"However the form also has a sub form which I also want any changes to be undone when the cancel button on the main form is clicked. "

Actually, I don't see how the situation can even occur.  If a SubForm record is dirty ... and you leave the subform, that record is now committed.  So, back on the main form, there is nothing to Undo on the Subform.

mx
You would need to see the form to understand the process and why this is necessary and why it is perfectly logical (the form and subform here are all fairly standard stuff).  But I think I will take JDettman's approach. Many thanks
"You would need to see the form to understand the process and why this is necessary"
Please enlighten me ... because if:

"the form and subform here are all fairly standard stuff"
 ... then once you leave the subform ... back to the main Form, there is nothing left to Undo on the subform ... *assuming* the subform is a bound form, and by 'standard stuff' ... you are implying that is the case.

So, please tell me why ... the subform record would still be 'dirty' (in edit) if you click back onto the main form ?

mx
Seems straightforward to me although I don't think I mentioned that this is particularly relevant when editing records.  

So user opens record, changes something on the main form, changes something on the sub form and then decides that they don't want to make the changes.   So  the aim is that they click the Cancel button which rolls back the changes on both the main form and sub form.

I realise not straightforward to achieve but it does seem a fairly standard situation.


I see. Well, then I vote for # 1 ... and here is a example db of how to do that by EE's Leigh Purvis:

http://www.databasedevelopment.co.uk/examples.htm

Scroll down to :

"Transactions In Forms (Download FormTransaction.zip)
A test bed showing how ADO and DAO recordsets can wrap bound form functionality.
While not comprehensive or clean - it shows the basics of how to achieve it. For full such control consider a combination of other techniques, e.g. Unbound or Disconnected data. "

It also gives a good lesson in Transactions in general.

mx