Solved

Rolling back transactions in Access (using ADO, DAO, Access code, whatever)

Posted on 2003-12-11
6
1,039 Views
Last Modified: 2013-11-27
I'm a SQL programmer, fairly new to Access...

I have an Access database that I created a form in, within the form, I want to run several action queries (to insert data, update data, and delete other data) over a series of 4 queries.  If any of them fail, I need to roll them all back.  I thought the ability to rollback would be inherent to Access 2000 but apparently not.

I tried to use ADO since I am familiar with that, but two problems:
1. ADO asks for the path of the file - that is really redundant since I am IN the database that I want to interact with, but I provided it the path anyway.
2. When I try to open the database that I am ALREADY IN,  it tells me that (80004005) "database has been placed in a state that prevents it from being open or locked"

Should I be using DAO?  Is there a better way to connect using ADO?  Can I use functions and calls inherent to VBA or A2000 that will allow rollbacks.

Thanks for your time.

Paul

0
Comment
Question by:PaulBarbin
  • 3
  • 2
6 Comments
 
LVL 39

Accepted Solution

by:
stevbe earned 500 total points
ID: 9923637
DAO makes it very simple ...

Public Function TRANS()

Dim blnTrans As Boolean
Dim ws As DAO.Workspace

On Error GoTo ERR_TRANS

Set ws = DBEngine(0)

ws.BeginTrans
    blnTrans = True
    DBEngine(0)(0).Execute ...blah your SQL, dbFailOnError
    DBEngine(0)(0).Execute ...blah your SQL, dbFailOnError
    DBEngine(0)(0).Execute ...blah your SQL, dbFailOnError
ws.Committrans

EXIT_TRANS:
   Set ws = Nothing
    Exit Function
ERR_TRANS
   If blnTrans = True Then
      ws.Rollback
  End If
  Resume EXIT_TRANS
End Function

Steve
0
 
LVL 9

Author Comment

by:PaulBarbin
ID: 9924155
Thanks Steve, worked like a champ.  I didn't want to jump into DAO, but its not as scary as I thought.

Paul
0
 
LVL 39

Expert Comment

by:stevbe
ID: 9929826
you are welcome, I have not done transactions with ADO yet but I am sure it is possible. Thanks for the points.

Steve
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 39

Expert Comment

by:stevbe
ID: 9929892
I crack me up ... here is a link to a question I answered a while ago on how to do transactions with ADO...

http://www.experts-exchange.com/Databases/MS_Access/Q_20734189.html#9928326

Steve
0
 
LVL 9

Author Comment

by:PaulBarbin
ID: 9930231
I had seen a link with that and tried it "currentproject.connection", but it didn't work - I probably typo'd it.  I am much more familiar with ADO and would have preferred that route.  Thanks again for the help.

Paul
0
 
LVL 26

Expert Comment

by:Alan Warren
ID: 9935855
Hi Steve,

Wondering if you might look into an excel question for me,
Re: Sharing conflicts with excel linked tables.
The guy is losing heart, so I told him I would try to find the excel dude (you) LOL

http://www.experts-exchange.com/Databases/MS_Access/Q_20824776.html

Sorry for spamming your post Paul.

Alan :)
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now