Solved

Main form and subform "undo"

Posted on 2001-08-14
14
1,002 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

 
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
 
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

Independent Software Vendors: 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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Access Report Expression 4 26
MS Access, How to create variable 9 37
Append Query Access 2010 4 25
Trying to figure out how to design a form 4 21
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

749 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