ACC2000: Error Using CurrentProject.Connection in TransactionsID: Q223213
|
If you use the CommitTrans or RollbackTrans methods directly with the CurrentProject.Connection object, you may receive one of the following errors:
You tried to commit or rollback a transaction without first beginning a transaction.
-or-
No transaction is active.
Each time the CurrentProject.Connection object is used, it has a different pointer to the connection. In effect, the instance or pointer to that object is temporary. This is why you see no error on CurrentProject.Connection.BeginTrans, but you do receive an error once you try to commit or rollback the transaction.
Microsoft provides programming examples for illustration only, without warranty
either expressed or implied, including, but not limited to, the implied warranties of
merchantability and/or fitness for a particular purpose. This article assumes that you
are familiar with the programming language being demonstrated and the tools used to
create and debug procedures. Microsoft support professionals can help explain the functionality
of a particular procedure, but they will not modify these examples to provide added
functionality or construct procedures to meet your specific needs. If you have limited
programming experience, you may want to contact a Microsoft Certified Solution Provider
or the Microsoft fee-based consulting line at (800) 936-5200. For more information about
Microsoft Certified Solution Providers, please see the following page on the World Wide Web:
http://www.microsoft.com/mcsp/For more information about the support options available from Microsoft, please see the following page on the World Wide Web:
http://www.microsoft.com/support/supportnet/overview/overview.aspCAUTION: Following the steps in this example will modify the sample database Northwind.mdb. You may want to back up the Northwind.mdb file and perform these steps on a copy of the database.
Sub tstConnectionObj()
Dim c As ADODB.Connection
Dim rs As ADODB.Recordset
Set c = CurrentProject.Connection
Set rs = New ADODB.Recordset
rs.Open "Categories", c, adOpenDynamic, adLockOptimistic
c.BeginTrans
rs.Fields(1) = "Drinks"
rs.Update
MsgBox "Updated field to " & rs.Fields(1) & "."
c.RollbackTrans
rs.Requery
MsgBox "Rolled back field to " & rs.Fields(1) & "."
End Sub
tstConnectionObj
Note that you see the following message:Updated field to Drinks.
Rolled back field to Beverages.
Sub tstCurrentProj()
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
rs.Open "Categories", CurrentProject.Connection, adOpenDynamic, _
adLockOptimistic
CurrentProject.Connection.BeginTrans
rs.Fields(1) = "Drinks"
rs.Update
MsgBox "Updated field to " & rs.Fields(1) & "."
CurrentProject.Connection.RollbackTrans
MsgBox "Rolled back field to " & rs.Fields(1) & ".
End Sub
tstCurrentProj
Note that you see the following message:Updated field to Drinks.
Additional query words: prb
Keywords :
Version : WINDOWS:2000
Platform : WINDOWS
Issue type : kbprb
Last Reviewed: July 6, 1999