PDA

View Full Version : Really Stupid Question


tom_richardson
07-18-03, 11:22
Hi All,

I am trying to launch an access 97 database (.mdb) from an Excel 97 spreadsheet, using the following code attached to a button:

Sub CommandButton13_Click()
Dim oAccApp As Object
Set oAccApp = CreateObject("Access.Application")
oAccApp.Application.Visible = True
oAccApp.Application.OpenCurrentDatabase "<PATH HERE>\database.mdb"
End Sub

It's working fine except for one thing: access is loading up the database but only for a split second then instantly disappearing again. I know this is probably really obvious but can anyone help me?

Many Thanks,
Tom Richardson

rwcplw
08-02-03, 14:52
Your oAccApp exists only for a split second because your Function CommandButton13_Click() only exists on the Stack for a split second.

Assuming that you want the oAccApp to persist, then you must make it a variable declared at the Module level.

Something like:


Option Explicit
Dim oAccApp As Object

Sub CommandButton13_Click()
Set oAccApp = CreateObject("Access.Application")
oAccApp.Application.Visible = True
oAccApp.Application.OpenCurrentDatabase "<PATH HERE>\database.mdb"
End Sub

-- Mike