UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> Want To Use Transactions On Mainform/subform Set Up    
 
   
Kamulegeya
post Mar 31 2012, 12:33 PM
Post #1

UtterAccess Ruler
Posts: 1,291
From: Kampala,Uganda The Pearl of Africa



Hello UA

I have main form with a continuous sub form

I want the user to be able to commit all edits once.

So i have this global constant in a module
CODE
Public blInTransaction As Boolean


in the subform dirty event i have

CODE
Private Sub Form_Dirty(Cancel As Integer)
'user starts an edit, and start a transaction if required
If blInTransaction = False Then
' if not in a transaction then start one
DBEngine.BeginTrans
End If
blInTransaction = True
End Su


In the open event of the subform i have
CODE
Private Sub Form_Open(Cancel As Integer)
Dim rs As DAO.Recordset
Set rs = Me.RecordsetClone
blInTransaction = False
End Sub



On the main form i have the save button

CODE
Private Sub cdmSave_Click()
If blInTransaction = True Then
If MsgBox("Do you want to commit all changes?", vbYesNo) = vbYes Then
DBEngine.CommitTrans dbForceOSFlush
Else
DBEngine.Rollback
End If
End If
End Sub


If i change record on subform, and click save, the message box appears, but it looks like the changes are already committed because clicking no does not undo the changes.


Anyway to make it work?


I am open to an alternative solution

Ronald
Go to the top of the page
 
+
arnelgp
post Mar 31 2012, 12:42 PM
Post #2

UtterAccess Ruler
Posts: 1,090



If it is a bound form/controls then the save is automatically commited.
You can't use Transaction in that case.
Go to the top of the page
 
+
Kamulegeya
post Mar 31 2012, 12:56 PM
Post #3

UtterAccess Ruler
Posts: 1,291
From: Kampala,Uganda The Pearl of Africa



QUOTE (arnelgp @ Mar 31 2012, 08:42 PM) *
If it is a bound form/controls then the save is automatically commited.
You can't use Transaction in that case.



Hello

On a single continuous form it works

Failed to pull it off on a subform

Ronald
Go to the top of the page
 
+
arnelgp
post Mar 31 2012, 01:09 PM
Post #4

UtterAccess Ruler
Posts: 1,090



If you swith from Main form to subform or vice versa, changes are committed automatically, on which ever form has lost it focus.
Go to the top of the page
 
+
Kamulegeya
post Mar 31 2012, 01:58 PM
Post #5

UtterAccess Ruler
Posts: 1,291
From: Kampala,Uganda The Pearl of Africa



It seems no subform event can help me pull off this...tried lostfocus...failed

Gave up


Ronald
Go to the top of the page
 
+
BananaRepublic
post Mar 31 2012, 04:35 PM
Post #6

Rent-an-Admin
Posts: 8,762
From: Banana Republic



The only way to do this with a bound form is with a MySQL backend.

In all other cases, I'd just use a temporary local Access table that loads the records to be viewed and propagate back the changes.
Go to the top of the page
 
+

Thank you for your support! Reply to this topicStart new topic

Jump To Forum:
 



RSS Go to Top  ·  Lo-Fi Version Time is now: 20th May 2013 - 09:30 PM