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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Transaction Help 1

Status
Not open for further replies.

jwigal

Programmer
Mar 16, 2001
31
US
So, this is my first go-around with trying to write ADO transactions into an Access database. Nothing fancy, just trying to work with a single-file Access DB.

Here's an example of syntax that I can't figure out why is failing:

Code:
Function TestTransaction(commit As Boolean)

CurrentProject.Connection.BeginTrans

CurrentProject.Connection.Execute "INSERT INTO ErrorLog ([User]) VALUES ('Hey There');"

If commit Then
    CurrentProject.Connection.CommitTrans
Else
    CurrentProject.Connection.RollbackTrans
End If

End Function

When I run TestTransaction with either a value of true or false, it fails with the error:

You tried to commit or rollback a transaction without first beginning a transaction.

What am I doing wrong?



----------
Jeff Wigal
jeff@wigaldesign.com
Referee Assistant for MS Access
 
Could you try declaring a connection object:

[tt]dim cn as adodb.connection
set cn = currentproject.connection
cn.BeginTrans

cn.Execute "INSERT INTO ErrorLog ([User]) VALUES ('Hey There');"

If commit Then
cn.CommitTrans
Else
cn.RollbackTrans
End If[/tt]

Roy-Vidar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top