Creates a new
Workspace object.
Syntax
expression.CreateWorkspace(Name, UserName, Password, UseType)
expression A variable that represents a DBEngine object.
Parameters
Return Value
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.
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.
Example
This example uses the CreateWorkspace method to createMicrosoft Access workspace. It then lists the properties of the workspace.
| Visual Basic for Applications |
|---|
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
|