Class Workspace (DAO VBA)
A Workspace object defines a named session for a user. It contains open databases and provides mechanisms for simultaneous transactions and, in Microsoft Access workspaces, secure workgroup support.
Class DBEngine gives access to class Workspace.
Dim wrk as Workspace
Set wrk = Workspaces(Item:=1)
Methods
OpenDatabase - Opens a specified database in a Workspace object and returns a reference to the Database object that represents it.
Sub OpenDatabaseX()
Dim wrkAcc As Workspace
Dim dbsNorthwind As Database
Dim dbsPubs As Database
Dim dbsPubs2 As Database
Dim dbsLoop As Database
Dim prpLoop As Property
' Create Microsoft Access Workspace object.
Set wrkAcc = CreateWorkspace("", "admin", "", dbUseJet)
' Open Database object from saved Microsoft Access database
' for exclusive use.
MsgBox "Opening Northwind..."
Set dbsNorthwind = wrkAcc.OpenDatabase("Northwind.mdb", _
True)
' Open read-only Database object based on information in
' the connect string.
MsgBox "Opening pubs..."
' Note: The DSN referenced below must be set to
' use Microsoft Windows NT Authentication Mode to
' authorize user access to the Microsoft SQL Server.
Set dbsPubs = wrkAcc.OpenDatabase("Publishers", _
dbDriverNoPrompt, True, _
"ODBC;DATABASE=pubs;DSN=Publishers")
' Open read-only Database object by entering only the
' missing information in the ODBC Driver Manager dialog
' box.
MsgBox "Opening second copy of pubs..."
Set dbsPubs2 = wrkAcc.OpenDatabase("Publishers", _
dbDriverCompleteRequired, True, _
"ODBC;DATABASE=pubs;DSN=Publishers;")
' Enumerate the Databases collection.
For Each dbsLoop In wrkAcc.Databases
Debug.Print "Database properties for " & _
dbsLoop.Name & ":"
On Error Resume Next
' Enumerate the Properties collection of each Database
' object.
For Each prpLoop In dbsLoop.Properties
If prpLoop.Name = "Connection" Then
' Property actually returns a Connection object.
Debug.Print " Connection[.Name] = " & _
dbsLoop.Connection.Name
Else
Debug.Print " " & prpLoop.Name & " = " & _
prpLoop
End If
Next prpLoop
On Error GoTo 0
Next dbsLoop
dbsNorthwind.Close
dbsPubs.Close
dbsPubs2.Close
wrkAcc.Close
End Sub
BeginTrans - Begins a new transaction.
Close - Closes an open Workspace.
CommitTrans - Ends the current transaction and saves the changes.
CreateDatabase - Creates a new Database object, saves the database to disk, and returns an opened Database object (Microsoft Access workspaces only).
OpenConnection - expression .OpenConnection(Name, Options, ReadOnly, Connect)
Rollback - Ends the current transaction and restores the databases in the Workspace object to the state they were in when the current transaction began.
Properties
Databases (Default member) - Returns a Databases collection that represents the open databases in the specified Workspace.
Connections returns a Connections collection that represents the current connections in the specified Workspace.
DefaultCursorDriver expression .DefaultCursorDriver
Groups
hEnv
IsolateODBCTrans sets or returns a value that indicates whether multiple transactiond that involve the same Microsoft Access database engine-connected ODBC data source are isolated (Microsoft Access workspaces only).
LoginTimeout sets or returns the number of seconds before an error occurs when you attempt to log on to an ODBC database.
Name returns or sets the name of the specified object. Read/write String if the object has not been appended to a collection.
Properties returns the Properties collection of the specified object.
Type sets or returns a value that indicates the operational type or data type of an object.
UserName
Users
Related Classes
Database - A Database object represents an open database.
Databases - A Databases collection contains all open Database objects opened or created in a Workspace object.
Properties - A Properties collection contains all the Property objects for a specific instance of an object.