Ok, a few more questions...
In my situation I have a procedure that calls sub procedures that update,
insert, delete rows etc.. etc..
If I begin a transaction in the main calling procedure, am I able to use the
"currentdb.execute strSQL dbfailonerror" code in all called sub procedures
and have those sub procedures be WITHIN the same transaction I started from
the main calling procedure? - so that if any called sub fails, then when
I get back to the main calling procedure and issue the rollback - will it
rollback all the updates etc.. that have happened in the various called
subs??
Here is some sample code how I would handle it - assuming what I want to do
above can be done...
Also, instead of dimming a db object, can I just use the
"currentdb.exeecute" statement?? (as shown in the 'called' subroutine below)
Example...
Sub MainSub(strQuoteNo as string)
'**** Main sub
dim ws as dao.workspace
dim db as dao.database
dim strSQL as string
dim bTransAct as boolean
dim bSubFailed as sboolean
on error goto SQL_ErrorMsg
' Set subroutine failed flag to false
bSubFailed = false
' start a trans
set ws = dbengine(0)
ws.begintrans
bTransAct = true
set db = ws(0)
strSQL = "delete from Quotes where QuoteNo=" & strQuoteNo
db.execute strSQL dbFailOnError
' Call another subroutine to insert some rows
call InsertSub
' Check to see if the sub failed - if so, roll back...
if bSubFailed then
goto SQL_Error
else
' Commit it!
ws.commitTrans
bTransAct = false
endif
SQL_Error:
on error resume next
set db = nothing
if bTransAct then
ws.rollback
endif
set ws = nothing
exit sub
SQL_ErrorMsg:
msgbox "Error: " & err.number
resume SQL_Error
end sub
***** Called Sub routine
Sub InsertSub
dim strSQL as string
on error goto SQL_Error
strSQL = "insert into QUOTES fields (fld1, fld2, fld3) values (val1, val2,
val3)"
currentdb.execute strSQL dbFailOnError
exit sub
SQL_Error:
' Set flag to indicate to calling sub that this sub failed
bSubFailed = true
end sub
"Allen Browne" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> Yes. You can RollBack or CommitTrans in DAO.
>
> There are several traps. For a discussion and example, see:
> Archive: Move records to another table
> at:
> http://allenbrowne.com/ser-37.html
>
> --
> Allen Browne - Microsoft MVP. Perth, Western Australia.
> Tips for Access users - http://allenbrowne.com/tips.html
> Reply to group, rather than allenbrowne at mvps dot org.
>
> "Brad Pears" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> Can Access 2000 even support transaction processing? I have an area in an
>> existing application that would be ripe for a begin/end and rollback if
>> user cancels the process... I am currently just using DAO in this app.
>> It is scheduled for redevelopment in VB .net 2005 and using SQL server
>> 2000 instead - which obviously supports transaction processsing. Just do
>> not know whow long this app will actually live in it's current state -
>> hence thinking about adding some Xaction processing to existing app...
>>
>> Thanks,
>>
>> Brad
>
>