Wrox Home  
Search P2P Archive for: Go

  Return to Index  

access thread: How can i undo changes in a subform?


Message #1 by gail711@g... on Thu, 19 Jul 2001 09:47:58
   I have made a form with a subform and have an undo button on the form.  

when you click on the button it will check if the form has changes undo 

them, then checks if the subform has changes but it doesn't undo them.



this is the code, how can i specify to undo the subform changes with the 

docmd?



Dim frm As Form

  Set frm = Forms!frmabsencesf

 

  If Me.Dirty Then  'something has been input

    If MsgBox("Data has been changed@@Do you wish to abandon changes?", 

vbYesNo, "Abandon Changes") = vbYes _

       Then DoCmd.RunCommand acCmdUndo

  End If

  

  If frm.Dirty Then

   If MsgBox("Data has been changed@@Do you wish to abandon changes?", 

vbYesNo, "Abandon Changes") = vbYes _

       Then DoCmd.RunCommand acCmdUndo

   End If
Message #2 by "Pardee, Roy E" <roy.e.pardee@l...> on Thu, 19 Jul 2001 10:03:14 -0700
Yes, I've wanted to do this too recently--here's my understanding of the

problem.



I believe the crux is that forms' Undo method can only undo changes made to

the current record on the form.  With subforms that are shown in datasheet

mode (which is typically how I'm using them) the user can of course change

multiple records on the subform, only the last of would be undoable (except

that when they click on your Undo button the subform loses focus & so even

the last changes are committed, so to speak).



The only way out of this that I know of is to use transactions.  In a

nutshell, you've got to re-bind your forms at runtime (both main and

subforms), using recordsets that are derived from an explicitly defined

Workspace object.  You manage the transactions by calling the .BeginTrans

.CommitTrans and .Rollback methods.  It's a pretty big pain in the butt...



If you're interested in going this way, you should really have a look at

Getz, Litwin & Gilbert's _Access 2000 Developer's Handbook Vol. I_.  The

material of interest is on page 578.



HTH,



-Roy



-----Original Message-----

From: gail711@g... [mailto:gail711@g...]

Sent: Thursday, July 19, 2001 2:47 AM

To: Access

Subject: [access] How can i undo changes in a subform?





   I have made a form with a subform and have an undo button on the form.  

when you click on the button it will check if the form has changes undo 

them, then checks if the subform has changes but it doesn't undo them.



this is the code, how can i specify to undo the subform changes with the 

docmd?



Dim frm As Form

  Set frm = Forms!frmabsencesf

 

  If Me.Dirty Then  'something has been input

    If MsgBox("Data has been changed@@Do you wish to abandon changes?", 

vbYesNo, "Abandon Changes") = vbYes _

       Then DoCmd.RunCommand acCmdUndo

  End If

  

  If frm.Dirty Then

   If MsgBox("Data has been changed@@Do you wish to abandon changes?", 

vbYesNo, "Abandon Changes") = vbYes _

       Then DoCmd.RunCommand acCmdUndo

   End If
Message #3 by "Peter Kaufman" <kaufman@l...> on Fri, 20 Jul 2001 19:47:58 +0700
Another way is shown in the solutions.mdb from MS if it is still available.

Basically it involves  copying the data over to 'temporary' tables and then

replacing the new data if the user cancels.



HTH,



Peter



> -----Original Message-----

> From: Pardee, Roy E [mailto:roy.e.pardee@l...]

> Sent: Friday, July 20, 2001 12:03 AM

> To: Access

> Subject: [access] RE: How can i undo changes in a subform?

>

>

> Yes, I've wanted to do this too recently--here's my understanding of the

> problem.

>

> I believe the crux is that forms' Undo method can only undo

> changes made to

> the current record on the form.  With subforms that are shown in datasheet

> mode (which is typically how I'm using them) the user can of course change

> multiple records on the subform, only the last of would be

> undoable (except

> that when they click on your Undo button the subform loses focus & so even

> the last changes are committed, so to speak).

>

> The only way out of this that I know of is to use transactions.  In a

> nutshell, you've got to re-bind your forms at runtime (both main and

> subforms), using recordsets that are derived from an explicitly defined

> Workspace object.  You manage the transactions by calling the .BeginTrans

> .CommitTrans and .Rollback methods.  It's a pretty big pain in the butt...

>

> If you're interested in going this way, you should really have a look at

> Getz, Litwin & Gilbert's _Access 2000 Developer's Handbook Vol. I_.  The

> material of interest is on page 578.

>

> HTH,

>

> -Roy

>

>



Message #4 by "Richard Lobel" <richard@a...> on Fri, 20 Jul 2001 07:30:31 -0700
I would use Transactions in your code that writes the changes to the

database. Before writing any changes put into your code:

TheNameOfYourWorkspace or if you don't have one,

Workspaces(0).BeginTrans

Then write your changes

The code in your Cancel button should be:

YourWorkspace.Rollback

And when you want the changes written it should be:

YourWorkspace.Commit



Hope this helps,

Richard Lobel








  Return to Index