A
accessmonster3 via AccessMonster.com
I enjoy the ability proposed with transactions but it seems they actually
cause my vba to FAIL. This code works great IF I don't have the transaction
code, adding the begintrans etc cause it to fail on the SECOND customer with
odd errors like no current record or can't commit record without begin
transaction.
Sample Code Snippet
Set rstInvoice = CurrentDb.OpenRecordset("tbl_Invoice", dbOpenDynaset,
dbSeeChanges)
Set ws = DBEngine(0)
do while not rstCustomers.eof
ws.BeginTrans
InvoiceSub = 0
rstInvoice.AddNew
rstInvoice!InvoiceDate = Date
rstInvoice.Update
rstInvoice.Bookmark = rstInvoice.LastModified (**Qeustion 1: is this
really necessary? **)
newInvoiceID = rstInvoice!InvoiceID 'to easily reference what invoice id
we are working on
then a ton of code generating each line entry
InvoiceSub = InvoiceSub + eachline
rstInvoice.Edit (**Question 2: it fails here on the SECOND customer with
'no current record', why would it work the first time? it ONLY fails if the
transactions are being used otherwise everything works great**)
rstInvoice!Subtotal = InvoiceSub
rstInvoice.Update
If TransError then
ws.rollback
else
ws.committrans
end if
rstCustomers.MoveNext
Loop
cause my vba to FAIL. This code works great IF I don't have the transaction
code, adding the begintrans etc cause it to fail on the SECOND customer with
odd errors like no current record or can't commit record without begin
transaction.
Sample Code Snippet
Set rstInvoice = CurrentDb.OpenRecordset("tbl_Invoice", dbOpenDynaset,
dbSeeChanges)
Set ws = DBEngine(0)
do while not rstCustomers.eof
ws.BeginTrans
InvoiceSub = 0
rstInvoice.AddNew
rstInvoice!InvoiceDate = Date
rstInvoice.Update
rstInvoice.Bookmark = rstInvoice.LastModified (**Qeustion 1: is this
really necessary? **)
newInvoiceID = rstInvoice!InvoiceID 'to easily reference what invoice id
we are working on
then a ton of code generating each line entry
InvoiceSub = InvoiceSub + eachline
rstInvoice.Edit (**Question 2: it fails here on the SECOND customer with
'no current record', why would it work the first time? it ONLY fails if the
transactions are being used otherwise everything works great**)
rstInvoice!Subtotal = InvoiceSub
rstInvoice.Update
If TransError then
ws.rollback
else
ws.committrans
end if
rstCustomers.MoveNext
Loop