Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Form, subform, transaction

Status
Not open for further replies.

halx

Programmer
Jun 5, 2002
35
FR
Hello,

I have found a thread about using transactions to save data inserted in a form that contains a subform but I could not make the code work.

So here is my problem:
I have a form "frmTest" bound to the table "tblTests" and a subform "sfrmSteps" bound to the table "tblSteps". The form and the subform are linked by the field "IDTest".

How do I make a save button and a cancel button that acts on the current record of the form and on the records in the subform linked to the main form's record ?

Here is (part of) the code I use:

--------------------------------------------------------
Option Compare Database
Option Explicit

Dim cnn1 As ADODB.Connection
--------------------------------------------------------

Private Sub Form_Load()
Set cnn1 = CurrentProject.Connection
cnn1.BeginTrans
End Sub
--------------------------------------------------------

Private Sub btnSave_Click()
cnn1.CommitTrans
End Sub
--------------------------------------------------------

Private Sub btnCancel_Click()
cnn1.RollbackTrans
End Sub


What's wrong ?


Thanks,


Alex
 
I'd not go anywhere near Transactions for this.

I'd be looking at something like:-

Private Sub btnSave_Click()
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
End Sub
--------------------------------------------------------

Private Sub btnCancel_Click()
Me.Undo
End Sub


'ope-that-'elps.

G LS
 
Hello,

Thanks for your post, but unfortunately, things are not that simple.
What I want to do is to save the data in the form and the data in the subform AT THE SAME TIME.

The subform is in data sheet view, so when you move from one record to another inside that form, Access saves automatically.

I am pretty sure I need to use transactions to avoid this, but I do know how to implement them.
Does anybody have an example in a .mdb file ?

Thanks,

Alex
 
Access saves automatically when you move between records in a form regardless of the layout of the form itself.

Are you saying that you want to be able to make changes to multiple records on the sub Form AND on the main form - THEN decide to RollBack the whole set of multi-record changes ?

G LS
 
Hello,

Yes, I would like to do that (ie: to save or cancel ALL the changes, with a Save and a Cancel button). I need to use BeginTrans, CommitTrans and RollBackTrans, but I don't know the implementation.

Do you know where on the web I could find an example of a form with a subform using transactions to do that ?

Thanks,

Alex


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top