Difference between DBEngine.BeginTrans and DBEngine.Workspaces (0) .BeginTrans

In Access, what is the difference between these two statements?

DBEngine.BeginTrans 

and

 DBEngine.Workspaces(0).BeginTrans 

Documentation for both leads to the same place.

+6
ms-access transactions
source share
4 answers

My own answer:

It looks like DBEngine.BeginTrans and DBEngine.Workspaces (0) .BeginTrans do the same thing because this code works (see below). Workspaces is the default DBEngine member.

 Dim db As Database Set db = CurrentDb DBEngine.BeginTrans db.Execute "Update Table1 SET CITY='Newark'" DBEngine.Workspaces(0).Rollback 
+2
source share

Take a look here: DAO workspace
And then here: DAO workspace: opening a separate transaction space

(The links are for MFC, but they apply to everything you encode.)

DBEngine.Workspaces(0) is the default workspace. You can create other workspaces that allow you to work with individual sessions; the idea is that BeginTrans and EndTrans apply to the entire workspace, but if you need to do something outside of this transaction, you can create another workspace and use it independently of your transactions in the first workspace.

Personally, I have never had to use more than one workspace when running a DAO in VBA. * shrug *

+7
source share

In the Access application interface, you can open only one database container at a time. In VBA code, you can open multiple database instances in the workspace. See the Help file documentation for the Workspace.OpenDatabase method (or http://msdn.microsoft.com/en-us/library/bb243164.aspx ) for an example when multiple databases are open on the same workspace.

It could be concluded that when transactions are supported by all the underlying databases open in the workspace, the BeginTrans method of the workspace will be applied to all databases. I suspect there are dragons there, but I'm sure it will work with two MDBs within the same workspace. When only one database is open in the workspace, Workspace.BeginTrans and Database.BeginTrans really match.

0
source share

As Spock once said, a difference that makes no difference is not a difference ...

0
source share

All Articles