CreateObject - start Access from Excel

  • Thread starter Thread starter Piers 2k
  • Start date Start date
P

Piers 2k

Hi folks,

Am trying to start an Access database from VBA, but it closes itself when
the code finishes. I simply don't want this to happen. The following code
works fine if I change the Access into Word (see the comment):

Sub StartApp()

Dim OtherApp As Object

' Set OtherApp = CreateObject("Word.Application")
Set OtherApp = CreateObject("Access.Application")

OtherApp.Visible = True

End Sub

Any help please?
TIA,

Piers
 
Roedd said:
Hi folks,

Am trying to start an Access database from VBA, but it closes itself
when the code finishes. I simply don't want this to happen. The
following code works fine if I change the Access into Word (see the
comment):

Sub StartApp()

Dim OtherApp As Object

' Set OtherApp = CreateObject("Word.Application")
Set OtherApp = CreateObject("Access.Application")

OtherApp.Visible = True

End Sub

Any help please?
TIA,

Piers

Move the declaration (Dim statement) outside the sub procedure. The variable
is going out of scope when the procedure exits and this kills the
application it refers to.
 

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

Back
Top