J
j_gold
Hi,
I have a class module. When I call it from my form module, I get the error
3034 "You tried to commit or rollback a transaction without first beginning a
transaction".
What am I missing
Thanks,
J Gold
Option Compare Database
Option Explicit
Private wrkSpace As DAO.Workspace
Private dbUnit As DAO.Database
Private Sub Class_Initialize()
Set wrkSpace = DBEngine(0)
Set dbUnit = CurrentDb
End Sub
Public Function add_unit(newUnitID As Integer, newUnitType As String,
newUnitName As String, _
newBuildingName As String, newBuildingAddress As String,
newRoomNumber As String) As Boolean
Dim sqlQuery As String
Dim intDAOErrNo As Integer, intCtr As Integer
On Error GoTo ErrorHandler
sqlQuery = "INSERT INTO Unit (unitID, unitName, buildingName ,
buildingAddress, roomNumber, unitType) VALUES (" _
+ newUnitID + ",'" + newUnitName + " ','" + newBuildingName +
"','" + newBuildingAddress _
+ "','" + newRoomNumber + "','" + newUnitType + "')"
wrkSpace.BeginTrans
dbUnit.Execute sqlQuery
wrkSpace.CommitTrans dbForceOSFlush
Done:
Exit Function
ErrorHandler:
wrkSpace.Rollback
Resume ErrorHandler_Exit
ErrorHandler_Exit:
wrkSpace.Close
Exit Function
End Function
Private Sub Class_Terminate()
Set wrkSpace = Nothing
Set dbUnit = Nothing
End Sub
I have a class module. When I call it from my form module, I get the error
3034 "You tried to commit or rollback a transaction without first beginning a
transaction".
What am I missing
Thanks,
J Gold
Option Compare Database
Option Explicit
Private wrkSpace As DAO.Workspace
Private dbUnit As DAO.Database
Private Sub Class_Initialize()
Set wrkSpace = DBEngine(0)
Set dbUnit = CurrentDb
End Sub
Public Function add_unit(newUnitID As Integer, newUnitType As String,
newUnitName As String, _
newBuildingName As String, newBuildingAddress As String,
newRoomNumber As String) As Boolean
Dim sqlQuery As String
Dim intDAOErrNo As Integer, intCtr As Integer
On Error GoTo ErrorHandler
sqlQuery = "INSERT INTO Unit (unitID, unitName, buildingName ,
buildingAddress, roomNumber, unitType) VALUES (" _
+ newUnitID + ",'" + newUnitName + " ','" + newBuildingName +
"','" + newBuildingAddress _
+ "','" + newRoomNumber + "','" + newUnitType + "')"
wrkSpace.BeginTrans
dbUnit.Execute sqlQuery
wrkSpace.CommitTrans dbForceOSFlush
Done:
Exit Function
ErrorHandler:
wrkSpace.Rollback
Resume ErrorHandler_Exit
ErrorHandler_Exit:
wrkSpace.Close
Exit Function
End Function
Private Sub Class_Terminate()
Set wrkSpace = Nothing
Set dbUnit = Nothing
End Sub