• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1024
  • Last Modified:

Main form and subform "undo"

I have a main form with a tab control.  I have two tabs on the tab control.  I have created an undo button which successfully "undoes" the main form and controls on the first tabbed page.  The problem is that my 2nd tabbed page includes a subform.  I can't get the controls on the subform to "undo".  Any suggestions?
0
kearley
Asked:
kearley
  • 4
  • 4
  • 3
  • +3
1 Solution
 
mgrattanCommented:
What does your syntax look like?  It will probably need to look something like this:

Me!SubFormName.Form.Requery
0
 
GudareCommented:
Similar to MGrattan, but using Undo:

Me.SubFormControlName.Form.Undo
0
 
kearleyAuthor Commented:
The code mentioned does not work either. :(  On my main form, I have a tab control.  The first tab has 2 subforms on it.  The 2nd tab has 1 subform on it.  Here is the code beneath my undo button:

If Me.dirty then
    Me.Undo
Endif
If Me.fSub1.Form.Dirty then
    Me.fSub1.Form.Undo
Endif
If Me.fSub2.Form.Dirty then
    Me.fsub2.Form.Undo
Endif

Even though I'm changing field values on my subforms, the dirty property is staying "false".

Thanks.
   
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
mgrattanCommented:
Yeah, that's what I meant, Undo.  Must have been sleeping.
0
 
mgrattanCommented:
I don't think you can check the Dirty property of a subform; at least, I haven't had any luck with it in the past.  I would just do the Undo action based on some other logic; for example, the user clicks an Undo button on your form.  In my apps, I'll usually give the user an Undo button and then trigger its Enabled property by setting a flag in a global variable as soon as the user starts typing in the form or the subform.  If the flag is triggered, the form is "dirty".
0
 
archeryCommented:
I am assuming that your "Undo" button is on your mainform (maybe in footer ?). If you have made any changes on your subform, and then click on the "Undo" button, the subform "loses focus" and Access will AUTOMATICALLY update any record on the subform which have not been as yet updated (i.e. it is "dirty") which of course resets the "dirty" property for the subform to False. You have to come up with some other way to enable an "undo" to be done to the subform changes themselves (even maybe another "undo" button within the subform itself which only worries about its own "dirty" property (i.e. If me.dirty THEN ....). It is the "loss of focus" of the subform which is causing your problem
0
 
hotbudareCommented:
If u r using A2K or newer, the only way to undo changes in subform is by using VBA code to create and set your form and subform(s) recordsets, so you can enclose all your operations involving these recordsets within a single transaction, or better yet, one transaction for all operations performed since the form was opened and another one for all operations perfomed in each record belonging to your main form ...

HTH/EQTA
T.S.U. Mario Osorio
Punto Fijo, Falcon, Venezuela
0
 
Jim Dettman (Microsoft MVP/ EE MVE)PresidentCommented:
Just to add to the last comment.  If your not using A2K, then the only other option is to copy the data to temp tables.  Then discard if the user "undos" or update the main table if the user saves.

Main/subforms are a problem in that Access saves the main record when you go to a subform control.  Starting with A97 it happens as soon as the focus moves there.  In prior versions, it happened when you moved focus and then had a keypress.

Here's a MSKB article link that explains this and contains a link to another article showing you how to do a roll back with temp tables.

http://support.microsoft.com/support/kb/articles/Q132/0/33.asp

Jim.
0
 
kearleyAuthor Commented:
Thanks, Jim.  I actually have tried the solution from the knowledge base as you indicated.  It worked once for me when testing and the subsequent attempts have failed!  When it reaches the code to undo the subform, an error returns.  Here is my code:

UndoMain Me, "MainTableTemp"
UndoSub Me![ISU History Sub].Form, "HistoryTemp"
UndoSub Me![fsub_ITResource].Form, "ITTemp"
UndoSub Me![fsub_BAResource].Form, "BATemp"

The one time this did work successfully for me, I had reversed the order of the subform references putting the HIstory Sub prior to the fsub_ITResource.  Now when I test again, I am getting the error again.  The error I'm receiving is this:   'Run Time Error 2455.  You entered an expression that has an invalid reference to property Form/Report.  I've tried changing the names of my subform controls and can't get it to work!  Thanks for any additional help.


0
 
Jim Dettman (Microsoft MVP/ EE MVE)PresidentCommented:
Are you using the name of the subforms or the name of the subform controls?  It should be the name of the control, not the name of the subform itself.

Jim.
0
 
kearleyAuthor Commented:
Te name of my control.  The name of my subform and name of the control just happen to be exactly the same.  I tried changing the name of the control to something different and referencing the new name and it still doesn't work.  Thanks.
0
 
Jim Dettman (Microsoft MVP/ EE MVE)PresidentCommented:
Where exactly does the error occur?

Jim.
0
 
Jim Dettman (Microsoft MVP/ EE MVE)PresidentCommented:
I'm willing to look at this if you send along the MDB or did you find the problem?

Jim.
0
 
mgrattanCommented:
Solution?
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
  • 4
  • 3
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now