DAO Object
 
Workspaces collection contains all active, unhidden Workspace objects of the DBEngine object. (Hidden Workspace objects are not appended to the collection and referenced by the variable to which they are assigned.)
 

Remarks

Use the Workspace object to manage the current session or to start an additional session.
 
When you first refer to or use a Workspace object, you automatically create the default workspace, DBEngine.Workspaces(0). The settings of the Name and UserName properties of the default workspace are "#Default Workspace#" and "Admin," respectively. If security is enabled, the UserName property setting is the name of the user who logged on.
 
You can create new Workspace objects with the CreateWorkspace method. After you create a new Workspace object, you must append it to the Workspaces collection if you need to refer to it from the Workspaces collection. You can, however, use a newly created Workspace object without appending it to the Workspaces collection.
 
To refer to a Workspace object in a collection by its ordinal number or by its Name property setting, use any of the following syntax forms:
DBEngine.Workspaces(0)
DBEngine.Workspaces("name")
DBEngine.Workspaces![name]
 
 Note
ODBCDirect workspaces are not supported in Microsoft Access 2013. Use ADO if you want to access external data sources without using the Microsoft Access database engine.
 

Methods

Name
Description
Adds a new Workspace to the Workspaces collection.
Deletes the specified Workspace form the Workspaces collection.
Not supported for this object.
 

Properties

Name
Description
Returns the number of objects in the specified collection. Read-only.
 

Example

This example creates a new Microsoft Access Workspace object and appends it to the Workspaces collection. It then enumerates the Workspaces collections and the Properties collection of the Workspace object.
 
Sub WorkspaceX()
 
Dim wrkNewAcc As Workspace
Dim wrkLoop As Workspace
Dim prpLoop As Property
 
' Create a new Microsoft Access workspace.
Set wrkNewAcc = CreateWorkspace("NewAccessWorkspace", _
"admin", "", dbUseJet)
Workspaces.Append wrkNewAcc
 
' Enumerate the Workspaces collection.
For Each wrkLoop In Workspaces
With wrkLoop
Debug.Print "Properties of " & .Name
' Enumerate the Properties collection of the new
' Workspace object.
For Each prpLoop In .Properties
On Error Resume Next
If prpLoop <> "" Then Debug.Print " " & _
prpLoop.Name & " = " & prpLoop
On Error GoTo 0
Next prpLoop
End With
Next wrkLoop
 
wrkNewAcc.Close
End Sub
 
 
This example uses the CreateWorkspace method to create a Microsoft Access workspace. It then lists the properties of theworkspace.
 
Sub CreateWorkspaceX()
 
Dim wrkAcc As Workspace
Dim wrkLoop As Workspace
Dim prpLoop As Property
 
 
DefaultType = dbUseJet
' Create an unnamed Workspace object of the type
' specified by the DefaultType property of DBEngine
' (dbUseJet).
Set wrkAcc = CreateWorkspace("", "admin", "")
 
' Enumerate Workspaces collection.
Debug.Print "Workspace objects in Workspaces collection:"
For Each wrkLoop In Workspaces
Debug.Print " " & wrkLoop.Name
Next wrkLoop
 
With wrkAcc
' Enumerate Properties collection of Microsoft Access
' workspace.
Debug.Print _
"Properties of unnamed Microsoft Access workspace"
On Error Resume Next
For Each prpLoop In .Properties
Debug.Print " " & prpLoop.Name & " = " & prpLoop
Next prpLoop
On Error GoTo 0
End With
 
wrkAcc.Close
 
End Sub