VBA Code to Open a Microsoft Access Database From Within Great Plains

TechKnowledge Content


Is it possible to add a button to a Great Plains window and have VBA code open an existing Microsoft Access database when this button is clicked?


This can be done using Modifier and VBA.

1. Add a new button to the desired Great Plains window using Modifier.

2. Give this button a descriptive name such as btnOpenAccessDb.

3. Grant security to this modified window and then open the window itself in Great Plains.

4. Add the window to VBA and then add the new button to VBA as well.

5. Open the VBA editor and navigate to the code section for this Great Plains window. Following is a code sample that can be used here:

Option Explicit

Dim appAccess As Object

Private Sub btnOpenAccessDb_BeforeUserChanged(KeepFocus As Boolean, CancelLogic As Boolean)

Dim docAccess

Set appAccess = CreateObject("Access.Application")

docAccess = appAccess.OpenCurrentDatabase("C:\My Documents\db1.mdb", True)

appAccess.Visible = True

End Sub

Note -This code sample is designed to open adatabase named "db1.mdb" located in the C:\My Documents directory and can be changed as needed. The appAccess object should be dimensioned in the General Declarations section so that it persists beyond the scope of the button click event in which the code is firing.

This article was TechKnowledge Document ID:32879

Need more help?

Expand your skills
Explore Training
Get new features first
Join Microsoft Insiders

Was this information helpful?

Thank you for your feedback!

Thank you for your feedback! It sounds like it might be helpful to connect you to one of our Office support agents.