Solved

Main form and subform "undo"

Posted on 2001-08-14
14
968 Views
Last Modified: 2012-05-04
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
Comment
Question by:kearley
  • 4
  • 4
  • 3
  • +3
14 Comments
 
LVL 14

Expert Comment

by:mgrattan
ID: 6385938
What does your syntax look like?  It will probably need to look something like this:

Me!SubFormName.Form.Requery
0
 
LVL 2

Expert Comment

by:Gudare
ID: 6386085
Similar to MGrattan, but using Undo:

Me.SubFormControlName.Form.Undo
0
 

Author Comment

by:kearley
ID: 6386145
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
 
LVL 14

Expert Comment

by:mgrattan
ID: 6386146
Yeah, that's what I meant, Undo.  Must have been sleeping.
0
 
LVL 14

Expert Comment

by:mgrattan
ID: 6386154
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
 
LVL 4

Expert Comment

by:archery
ID: 6386584
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
 
LVL 2

Expert Comment

by:hotbudare
ID: 6386879
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 57
ID: 6388247
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
 

Author Comment

by:kearley
ID: 6389690
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
 
LVL 57
ID: 6389876
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
 

Author Comment

by:kearley
ID: 6389953
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
 
LVL 57

Accepted Solution

by:
Jim Dettman (Microsoft MVP/ EE MVE) earned 250 total points
ID: 6389977
Where exactly does the error occur?

Jim.
0
 
LVL 57
ID: 6392973
I'm willing to look at this if you send along the MDB or did you find the problem?

Jim.
0
 
LVL 14

Expert Comment

by:mgrattan
ID: 6393291
Solution?
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now