One Main form and one subform (1 Viewer)

fliu2265

New member
Local time
Yesterday, 23:48
Joined
Apr 29, 2022
Messages
4
Hello everyone,
I am just learning MS Access.
I created a Main form (Name: StaffUsers ) and a subform (Name: CalJOBS subform).
I put the Undo button on the Main Form. However when I click the Undo button on the main form, the entered data are cancelled on the Main form only
and the entered data are still in the subform. I would like to Undo all data in BOTH Main form AND subform.
The following is codes I write (not working so far). I have a form CalJOB subform, should I call it CalJOBS or [CalJOBS subform]?
**************************************
Private Sub Cancel_Click()
With Me
Call .Undo
Call .CalJOBS.Form.Undo
End With
Call DoCmd.Close
End Sub
******************************

I appreciate any help.

Frank
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 02:48
Joined
Feb 19, 2002
Messages
42,981
That's the way relational databases work and so that is how Access works. In order to add a child record to a table, its parent record must be added first. Access does this automatically for you when you move focus from a mainform to a subform and vice versa. Therefore, undo works ONLY on the current form's dirty record because that is the only record that has not been saved. It never affects any other records, especially those in a different table. Once a record is saved, it is not affected by undo.

If you want to get rid of both mainform and subform records, you must delete the main form record. If you have created relationships and specified cascade delete, then when you delete the mainform record, the child records will also be deleted. If you have not created relationships then, you MUST run a delete query to delete the child records followed by a delete of the main form record. If you delete the main form record without handling the child records, then you orphan them in database terms.
 
Last edited:

Mike Krailo

Well-known member
Local time
Today, 02:48
Joined
Mar 28, 2020
Messages
1,030
And why is this in the REPORTS area of the forum?
 

jdraw

Super Moderator
Staff member
Local time
Today, 02:48
Joined
Jan 23, 2006
Messages
15,364
@mike
Possibly:
New member.
No familiarity with forum sections.
New to Access.
Any answer is/could be helpful.
....
 

Users who are viewing this thread

Top Bottom