Link to home
Start Free TrialLog in
Avatar of kevin1973
kevin1973

asked on

Open Access File From Word

How can I use vba to open a specific file in Access from a Word toolbar button?  I've been able use the FollowHyperlink like a url but the window does not maximize.  This will need to work for both Word 97 and XP.  Any suggestions?
Avatar of pauloaguia
pauloaguia
Flag of Portugal image

After adding the Microsoft Access Object Library to your references (Tools -> References) you can use code like the following:

Sub startAcc()
    Dim accApp As Access.Application
   
    Set accApp = New Access.Application
    accApp.Visible = True
    accApp.OpenCurrentDatabase "c:\db1.mdb"
    accApp.DoCmd.Maximize
    accApp.Quit
End Sub

Hope this helps

Paulo
Avatar of Phetu
Phetu

Hi,

In order to complete pauloaquia solution, I would you to use this:

dim obj as object
Dim accApp As Object
Set accApp = CreateObject("access.application")

And at the end do:

Set accApp = Nothing

instead of your
Dim accApp As Access.Application
Set accApp = New Access.Application

That way you will prevent a bug that leave Access in memory when you close the application.
   
Hope it will help

Phetu
You're right, I forgot about the Set accApp = Nothing.
Thanks for the correction.

But the New operator will work just as well... (Or at least I think it will).
Hi pauloaquia,

No, there's a bug with the New operator that after you the quit instruction, "sometimes" the program stays in memory. Even after you quit you'll see the process still running without having the program runinng. It will be a kind of hidden process.

Few other member as complain about that and it could be applied to Excel or Word also.

That's why i make the precision.

Phetu
Ok, thanks again. You never stop learning...
No problem...that's why we are here for......
Avatar of kevin1973

ASKER

Using both suggestions I came up with the following which is semi working.  It open Access and the mdb file but then it closes it back out.  Access doesn't stay open and active.
Sub OpenAcc()

    Dim obj As Object
    Dim accApp As Object
    Set accApp = CreateObject("access.application")
    accApp.Visible = True
    accApp.OpenCurrentDatabase "d:\mydb.mdb"
    accApp.DoCmd.Maximize
    accApp.Quit
    Set accApp = Nothing

End Sub
Remove the accApp.Quit line. (But when the procedure ends and the accApp variable goes out of scope I think it will end anyway).

If you want to open a standalone application then I guess you can use

Application.ActivateMicrosoftApp xlMicrosoftAccess

but I don't know how to reference the Access application afterwards. But maybe it will shed a light to some other expert...

Paulo
I figured out a simple one liner to do the trick:

Shell ("c:\msoffice\office\msaccess.exe d:\mydb.mdb"), vbMaximizedFocus
When the problem is solved by the asker (s)he should post a 0 point question in Community Support Topic Area with a link to the first question asking for a moderator to come and close the question and refund the points.
I figured out a simple one liner to do the trick:

Shell ("c:\msoffice\office\msaccess.exe d:\mydb.mdb"), vbMaximizedFocus
ASKER CERTIFIED SOLUTION
Avatar of SpideyMod
SpideyMod

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial