ComitTrans in a Form

H

Herb

I have an MSAccess form in "continuous forms" mode that is bound to a table.
Records can be added, deleted and modified within the form but there is a
command box that allows the user to CANCEL.

Is there a way to use BeginTrans, ComitTrans and Rollback to accomplish this?

From what I've read about this feature it has to be based on a connection
object and the form does not really open a connection object that I can see.

Any help would be greatly appreciated.

Thank you
 
D

Dirk Goldgar

Herb said:
I have an MSAccess form in "continuous forms" mode that is bound to a
table. Records can be added, deleted and modified within the form but
there is a command box that allows the user to CANCEL.

Is there a way to use BeginTrans, ComitTrans and Rollback to
accomplish this?

From what I've read about this feature it has to be based on a
connection object and the form does not really open a connection
object that I can see.

Any help would be greatly appreciated.

Thank you

It appears that you can do it, at least in Access 2002, if you open your
own ADO recordset and bind the form to that recordset, rather than using
the built-in form binding. I have only experimented with it briefly, so
there may well be "gotchas" involved in the process.

This is the code module from my simple test form:

'----- start of code -----
Option Compare Database
Option Explicit

Dim mConn As ADODB.Connection

Private Sub Form_Close()

With mConn
If MsgBox("Rollback?", vbYesNo) = vbYes Then
.RollbackTrans
Else
.CommitTrans
End If
End With

Set mConn = Nothing

End Sub

Private Sub Form_Open(Cancel As Integer)

Dim rst As New ADODB.Recordset
Dim strSQL As String

Set mConn = CurrentProject.Connection
mConn.BeginTrans

rst.CursorLocation = adUseClient
rst.CursorType = adOpenStatic
rst.LockType = adLockOptimistic
strSQL = "SELECT * FROM Table1"
rst.Open strSQL, mConn

Set Me.Recordset = rst

End Sub

'----- end of code -----

Please note that I don't vouch for this technique at all. I only tested
it briefly.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

CommitTrans in Forms 3
Save data entered into a form 6
Duplicating records 3
Commit and RollBack in a Form 2
Form Undo Problem 1
Lock a form 3
Form permanently filtered? 4
Aborting form entry 12

Top