C
cboyda via AccessMonster.com
I admit it.. I don't quite fully understand how these transactions work, so
sure it works on iteration but fail for i+1.
This code works.. but then if any ONE item fails in the do until loop then
ALL transactions are rolled back.. I want to iterate through and if one fails
JUST that one is rolledback.
Code that works:
Set ws = DBEngine(0)
Set db = ws(0)
ws.BeginTrans
bInTrans = True
Do Until rstCustomers2Invoice.EOF
'Transaction init
'remember any sql statements called must include failonerror
' db.Execute strSql, dbFailOnError
Debug.Print
"**************************************************************************************"
CountCustomers = CountCustomers + 1
Debug.Print "Working on Customer Number " & CountCustomers & " of " &
MaxCustomers & " " & rstCustomers2Invoice!FirstName
RetVal = SysCmd(2, CountCustomers)
'start invoice
Set rstInvoice = db.OpenRecordset("tbl_invoice")
rstInvoice.AddNew
Code that I want.. that fails:
Set ws = DBEngine(0)
Set db = ws(0)
Do Until rstCustomers2Invoice.EOF
ws.BeginTrans
bInTrans = True
'Transaction init
'remember any sql statements called must include failonerror
' db.Execute strSql, dbFailOnError
Debug.Print
"**************************************************************************************"
CountCustomers = CountCustomers + 1
Debug.Print "Working on Customer Number " & CountCustomers & " of " &
MaxCustomers & " " & rstCustomers2Invoice!FirstName
RetVal = SysCmd(2, CountCustomers)
'start invoice
Set rstInvoice = db.OpenRecordset("tbl_invoice")
rstInvoice.AddNew
This fails on the rstInvoice.Addnew for the second iteration through the loop.
.. probably because db.openrecordset is now a second database connection.
ERROR 3420
Object Invalid or no longer set.
How can I fix this to get a transaction set for each iteration instead of the
whole group?
sure it works on iteration but fail for i+1.
This code works.. but then if any ONE item fails in the do until loop then
ALL transactions are rolled back.. I want to iterate through and if one fails
JUST that one is rolledback.
Code that works:
Set ws = DBEngine(0)
Set db = ws(0)
ws.BeginTrans
bInTrans = True
Do Until rstCustomers2Invoice.EOF
'Transaction init
'remember any sql statements called must include failonerror
' db.Execute strSql, dbFailOnError
Debug.Print
"**************************************************************************************"
CountCustomers = CountCustomers + 1
Debug.Print "Working on Customer Number " & CountCustomers & " of " &
MaxCustomers & " " & rstCustomers2Invoice!FirstName
RetVal = SysCmd(2, CountCustomers)
'start invoice
Set rstInvoice = db.OpenRecordset("tbl_invoice")
rstInvoice.AddNew
Code that I want.. that fails:
Set ws = DBEngine(0)
Set db = ws(0)
Do Until rstCustomers2Invoice.EOF
ws.BeginTrans
bInTrans = True
'Transaction init
'remember any sql statements called must include failonerror
' db.Execute strSql, dbFailOnError
Debug.Print
"**************************************************************************************"
CountCustomers = CountCustomers + 1
Debug.Print "Working on Customer Number " & CountCustomers & " of " &
MaxCustomers & " " & rstCustomers2Invoice!FirstName
RetVal = SysCmd(2, CountCustomers)
'start invoice
Set rstInvoice = db.OpenRecordset("tbl_invoice")
rstInvoice.AddNew
This fails on the rstInvoice.Addnew for the second iteration through the loop.
.. probably because db.openrecordset is now a second database connection.
ERROR 3420
Object Invalid or no longer set.
How can I fix this to get a transaction set for each iteration instead of the
whole group?