Background: I have a database in which I need to ensure that if a record exists in a certain parent table that a certain set of records exist in the child table. If a record is added to the parent table then certain related child records must be added. It's an all or nothing situation.
The article at https://support.microsoft.com/en-us/kb/248011 shows how to use transactions with a bound form. I created a small test database which is attached. It has a main form name frmParent which has a subform named sfrmChild. It has buttons to begin, commit or rollback a transaction. If you begin a transaction and then change something on the frmParent it doesn't get updated in the bound table ParentTable until you commit the transaction. So this work as it should. But this doesn't extend to the subform sfrmChild. Changes there update the table ChildTable even though there is a uncommitted transaction in progress.
One thing that I have found is key to this working is setting the forms record set to a DAO record set as it shows in the article, but I have done this in the sfrmChild on open event with
As an aside this wipes out the links which I restore in the frmParent's on open event.
So can anyone tell me why this isn't working? How do you get a transaction to work with both the form and subform?
The article at https://support.microsoft.com/en-us/kb/248011 shows how to use transactions with a bound form. I created a small test database which is attached. It has a main form name frmParent which has a subform named sfrmChild. It has buttons to begin, commit or rollback a transaction. If you begin a transaction and then change something on the frmParent it doesn't get updated in the bound table ParentTable until you commit the transaction. So this work as it should. But this doesn't extend to the subform sfrmChild. Changes there update the table ChildTable even though there is a uncommitted transaction in progress.
One thing that I have found is key to this working is setting the forms record set to a DAO record set as it shows in the article, but I have done this in the sfrmChild on open event with
Code:
Dim db As DAO.Database
Dim rs As DAO.Recordset
Set db = CurrentDb
Set rs = db.OpenRecordset("SELECT * FROM ChildTable", dbOpenDynaset)
Set Me.Recordset = rs
As an aside this wipes out the links which I restore in the frmParent's on open event.
So can anyone tell me why this isn't working? How do you get a transaction to work with both the form and subform?