Full Version: Cancel Update on a Subform
UtterAccess Forums > Microsoft® Access > Access Forms
stefanusmc
Hello,
I currently have a form where a user can open a record and either save or discard changes made. This form has three subforms, but I cant seem to find a way to undo changes made to the subforms. The code I am using on my main form is:
CODE
If save <> True Then DoCmd.RunCommand acCmdUndo
Which seems to work great, except I do not know enough about access to manipulate the subforms. Thanks in advance!
Jack Cowley
You may not be able to 'undo' the subforms. as the data may have already been committed. You may want to ensure Cascading Deletes for your related tables and delete the record on the main form which will delete the related records... If you don't you will end up with orphan records... Your other choice, as I understand your dilemma, is that you will need code to delete all child records with the same PK as the main form had...
th,
Jack
stefanusmc
My problem is not when deleting the record from my main form, it is when updating information. For example, one of my sub forms is for material used. If the user enters something, then later realizes it was entered to the wrong record, can this be undone? I now understand your point, is no longer a matter of undoing a change, but now a new record has been created with the subform. So there is really no way to "undo" a change to this subform without deleting the record on the master form? Forgive me if I am rambling, I am somewhat new to access. Thank you for your time.
Jack Cowley
The good news is that you are not rambling... You can delete the current record on the subform without deleting the record in the main form. There are a number of ways to do this and one would be to create a Delete command button, using the Wizard. Since I do not know if your subform is in Datasheet View or Single Form view I don't know if you can add a command button directly to your subform or not, but I think you can sort this out. If you have questions just ask!!!
omething to consider... You can add code to the subforms Before Update event and ask the user if they want to save the data they just entered. If they say No, then you can cancel the update then and there (the record will not be saved). If they do answer Yes and realize that that was wrong you can then use the command button to delete the record...
I hope this helps and don't be shy about asking as every one of us was a novice at one time or another....
Jack
LPurvis
Hi both.
My standard reference when discussing controlled form updates is this thread.
(Which I'd almost verbatim stated earlier without finding it - but by all means follow that link too to read it all again... man you'd think I *enjoy* typing :-s).
The points made therein reference certain example files I've made available too for demonstration purposes over time.
Not much point in me saying even more here yet - or I'll just be repeating myself again! ;-)
Cheers.
Jack Cowley
Leigh -
Thank you for the link to your erudite post!
You DO enjoy typing so just admit it and continue to flay away at your keyboard. We are all better informed because of this craving of yours to impart a modicum of your incredible store of knowledge to those of us less blessed.... And this is not tongue-in-cheek... or cheeky...
Jack
stefanusmc
Thank you so much for your help! This is exactly what I needed. Thank you everyone for taking the time to lend a hand to this access novice sad.gif
LPurvis
Ah you are too kind sir.
But thank you none the less - and it is my pleasure as always. thumbup.gif
You're welcome stefanusmc - glad you found it useful.
(And well done on reading it so quickly! ;-)
Cheers.
stefanusmc
LPurvis,
I have had some time to work with your example database on transactions. I have adapted it to my subforms, however my main form is unbound so it should be a non issue there. My subforms are all in datasheet view. Does this create an issue? I am not getting any errors, but the transaction itself doesnt seem to be working. When I load the form, the subforms are empty. If I modify the subforms, the table is immediately updated and I cannot use wrk.rollback to undo it. The code in the onLoad of my main form is as follows:
CODE
     Set wrk = Workspaces(0)
    Set db = CurrentDb
    Set rstJobDetailsEmployees = db.openRecordset("SELECT * FROM jobDetailsEmployees WHERE Jon = " & Me.Jon, dbOpenDynaset)
    Set rstJobDetailsMaterials = db.openRecordset("SELECT * FROM jobDetailsMaterials WHERE Jon = " & Me.Jon, dbOpenDynaset)
    Set rstComments = db.openRecordset("SELECT * FROM Comments WHERE Jon = " & Me.Jon, dbOpenDynaset)
    Set Me.jobDetailsEmployeesSubform.Form.Recordset = rstJobDetailsEmployees
    Set Me.jobDetailsMaterialsSubform.Form.Recordset = rstJobDetailsMaterials
    Set Me.Comments.Form.Recordset = rstComments
    
    wrk.BeginTrans
LPurvis
Well - while the transaction method isn't my favorite - it should work (at least for functional / demonstrational purposes for you).
Have you limited your main form to a single record? (Navigation issues make this the preferred method IMO).
ather than throw out random shots in the dark you might as well attach your test MDB.
stefanusmc
Ill clean up my DB and attach a copy tonight when I get home from work. My main form is unbound, and I use the doCmd.FindRecord cmd to access the appropriate record. Does I need to get rid of the FindRecord and open the table with a "Where" clause? I suppose that would make sense, then I could just wrap the whole thing up in the transaction instead of using the undo method on the main form. I will try that tonight before reposting. Thank you for your patients and insight.
This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.