You are currently offline, waiting for your internet to reconnect

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

Retired KB Content Disclaimer
This article was written about products for which Microsoft no longer offers support. Therefore, this article is offered "as is" and will no longer be updated.
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 a database 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

Article ID: 861457 - Last Review: 07/13/2012 08:44:00 - Revision: 4.0

Microsoft Dynamics GP 9.0, Microsoft Business Solutions–Great Plains 8.0, Microsoft Business Solutions–Great Plains 7.5, Microsoft Great Plains Dynamics 7.0, Microsoft Great Plains eEnterprise 7.0, Great Plains Dynamics 6.0, Great Plains eEnterprise 6.0, Modifier with Visual Basic for Applications

  • kbmbsmigrate kbretire KB861457