Nesting methods in Access VBA

J

JGPatrick

I would appreciate it if someone would clear up a confusion I have about VBA.
When is it OK and when is it not OK to nest methods?

For instance, the following code works fine:

Sub Prac1()

Debug.Print DBEngine.CreateWorkspace("WS1", "Admin", "", dbUseJet).Name

End Sub

But when I try to nest the CreateWorkspace method in the Workspaces.Append
method, the debug.print line generates an error message:

Sub Prac2()

Workspaces.Append DBEngine.CreateWorkspace("WS1", "Admin", "", dbUseJet)

debug.Print Workspaces(1).Name

End Sub
 
C

Clifford Bass via AccessMonster.com

Hi,

See the things I and others wrote about CurrentDB. They apply to the
CreateWorkspace method also. This works:

Sub Prac2()

Dim ws As DAO.Workspace

Set ws = DBEngine.CreateWorkspace("WS1", "Admin", "", dbUseJet)
Workspaces.Append ws

Debug.Print Workspaces(1).Name

End Sub

Clifford Bass
 
C

Clifford Bass via AccessMonster.com

Hi,

Glad it was helpful. I also learned some as I looked into it a bit
further than I had in the past.

Clifford Bass
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top