T
Tony Wainwright
Hey guys
A quick question regarding transactions. I am writing a application and to
streamline the the code I am breaking it in to seperate routines. What I
want to do is:
Public Sub InsertData()
On Error GoTo InsertDataErr
DoCmd.SetWarnings False
BeginTrans
vProc = True
Call Insert1stSetOfData
Call Insert2ndSetOfData
......
vProc = False
CommitTrans
InsertDataRes:
Exit Sub
InsertDataErr:
If vProc = True Then Rollback
......
End Sub
Public Sub Insert1stSetOfData()
BeginTrans
vSQL = "INSERT INTO tblName (FieldList) " _
& "VALUES (" & value1 & ", '" & value2 & "');"
DoCmd.RunSQL vSQL
CommitTrans
End Sub
Public Sub Insert2ndSetOfData()
BeginTrans
vSQL = "INSERT INTO tblName (FieldList) " _
& "VALUES (" & value1 & ", '" & value2 & "');"
DoCmd.RunSQL vSQL
CommitTrans
End Sub
I have read that CommitTrans is global and that you can nest tranactions.
If there is an error in either Insert2ndSetOfData will the data in
Insert1stSetOfData?
A quick question regarding transactions. I am writing a application and to
streamline the the code I am breaking it in to seperate routines. What I
want to do is:
Public Sub InsertData()
On Error GoTo InsertDataErr
DoCmd.SetWarnings False
BeginTrans
vProc = True
Call Insert1stSetOfData
Call Insert2ndSetOfData
......
vProc = False
CommitTrans
InsertDataRes:
Exit Sub
InsertDataErr:
If vProc = True Then Rollback
......
End Sub
Public Sub Insert1stSetOfData()
BeginTrans
vSQL = "INSERT INTO tblName (FieldList) " _
& "VALUES (" & value1 & ", '" & value2 & "');"
DoCmd.RunSQL vSQL
CommitTrans
End Sub
Public Sub Insert2ndSetOfData()
BeginTrans
vSQL = "INSERT INTO tblName (FieldList) " _
& "VALUES (" & value1 & ", '" & value2 & "');"
DoCmd.RunSQL vSQL
CommitTrans
End Sub
I have read that CommitTrans is global and that you can nest tranactions.
If there is an error in either Insert2ndSetOfData will the data in
Insert1stSetOfData?