CreateWorkspace Method
Applies To
DBEngine object.
Description
Creates a new Workspace object.
Syntax
Set workspace = CreateWorkspace(name, user, password, type)
The CreateWorkspace method syntax has these parts.
Part | Description |
|
workspace | An object variable that represents the Workspace object you want to create. |
name | A String that uniquely names the new Workspace object. See the Name property for details on valid Workspace names. |
user | A String that identifies the owner of the new Workspace object. See the UserName property for more information. |
password | A String containing the password for the new Workspace object. The password can be up to 14 characters long and can include any characters except ASCII character 0 (null). See the Password property for more information on valid passwords. |
type | Optional. A constant that indicates the type of workspace, as described in Settings. |
Settings
You can use the following constants for type.
Constant | Description |
|
dbUseJet | Creates a Microsoft Jet workspace. |
dbUseODBC | Creates an ODBCDirect workspace. |
Remarks
Once you use the CreateWorkspace method to create a new Workspace object, a Workspace session is started, and you can refer to the Workspace object in your application.
Workspace objects aren't permanent, and you can't save them to disk. Once you create a Workspace object, you can't alter any of its property settings, except for the Name property, which you can modify before appending the Workspace object to the Workspaces collection.
You don't have to append the new Workspace object to a collection before you can use it. You append a newly created Workspace object only if you need to refer to it through the Workspaces collection.
The type option determines whether the new Workspace is a Microsoft Jet or ODBCDirect workspace. If you set type to dbUseODBC and you haven't already created any Microsoft Jet workspaces, then the Microsoft Jet database engine will not be loaded into memory, and all activity will occur with the ODBC data source subsequently identified in a Connection object. If you omit type, the DefaultType property of DBEngine will determine which type of data source the Workspace is connected to. You can have both Microsoft Jet and ODBCDirect workspaces open at the same time.
To remove a Workspace object from the Workspaces collection, close all open databases and connections and then use the Close method on the Workspace object.
See Also
Close method, Name property, Password property, UserName property, Workspace object.
Example
This example uses the CreateWorkspace method to create both a Microsoft Jet workspace and an ODBCDirect workspace. It then lists the properties of both types of workspace.
Sub CreateWorkspaceX()
Dim wrkODBC As Workspace
Dim wrkJet As Workspace
Dim wrkLoop As Workspace
Dim prpLoop As Property
' Create an ODBCDirect workspace. Until you create
' Microsoft Jet workspace, the Microsoft Jet database
' engine will not be loaded into memory.
Set wrkODBC = CreateWorkspace("ODBCWorkspace", "admin", _
"", dbUseODBC)
Workspaces.Append wrkODBC
DefaultType = dbUseJet
' Create an unnamed Workspace object of the type
' specified by the DefaultType property of DBEngine
' (dbUseJet).
Set wrkJet = CreateWorkspace("", "admin", "")
' Enumerate Workspaces collection.
Debug.Print "Workspace objects in Workspaces collection:"
For Each wrkLoop In Workspaces
Debug.Print " " & wrkLoop.Name
Next wrkLoop
With wrkODBC
' Enumerate Properties collection of ODBCDirect
' workspace.
Debug.Print "Properties of " & .Name
On Error Resume Next
For Each prpLoop In .Properties
Debug.Print " " & prpLoop.Name & " = " & prpLoop
Next prpLoop
On Error GoTo 0
End With
With wrkJet
' Enumerate Properties collection of Microsoft Jet
' workspace.
Debug.Print _
"Properties of unnamed Microsoft Jet workspace"
On Error Resume Next
For Each prpLoop In .Properties
Debug.Print " " & prpLoop.Name & " = " & prpLoop
Next prpLoop
On Error GoTo 0
End With
wrkODBC.Close
wrkJet.Close
End Sub