Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

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


TechKnowledge Content

Issue


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?


Resolution


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

↑ Back to the top


Keywords: kbmbspartner, kbmbsmigrate, kbretire, kb

↑ Back to the top

Article Info
Article ID : 861457
Revision : 1
Created on : 1/7/2017
Published on : 7/13/2012
Exists online : False
Views : 90