Microsoft KB Archive/210192

= ACC2000: How to Determine Startup Folder of a Program =

Article ID: 210192

Article Last Modified on 10/11/2006

-

APPLIES TO


 * Microsoft Access 2000 Standard Edition

-



This article was previously published under Q210192



Advanced: Requires expert coding, interoperability, and multiuser skills.

This article applies to a Microsoft Access database (.mdb) and to a Microsoft Access project (.adp).



SUMMARY
You can use the SysCmd function to perform several functions. One of these functions is the acSysCmdAccessDir, which returns the name (\\) of the folder where Msaccess.exe is located. It does not return the name of the executable file, Msaccess.exe. This article includes two sample functions that you can use to return the name of the folder and the name of the executable file for any program running in the Microsoft Windows environment.

Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.



MORE INFORMATION
The CurDir function returns the current folder. Because you can start Access from a folder other than the current folder, and because you can change the current folder with the ChDir statement, you cannot use the CurDir function to determine the startup folder.

The following sample function uses the Windows API functions GetModuleHandle and GetModuleFileName. With the module handle, you can obtain the path with the GetModuleFileName function.   In a new database, create a module and type the following lines in the Declarations section: Option Explicit

Declare Function GetModuleHandle& Lib "kernel32" Alias _ "GetModuleHandleA" (ByVal FileName$)

Declare Function GetModuleFileName& Lib "kernel32" Alias _ "GetModuleFileNameA" (ByVal hModule&, ByVal FileName$, ByVal _     nSize&) NOTE: Aliases are case-sensitive.   Type the following procedure: Function StartUp_Dir Dim hModule&, Buffer$, Length&, Msg$ hModule& = GetModuleHandle("MSACCESS.EXE") Buffer$ = Space$(255) Length& = GetModuleFileName(hModule&, Buffer$, Len(Buffer$)) Buffer$ = Left$(Buffer$, Length&) Msg$ = "Startup path and filename: " & Buffer$ MsgBox Msg$ End Function

  To test this function, type the following line in the Immediate Window, and then press ENTER: ?StartUp_Dir Note that the Access startup folder and executable name are displayed in the Immediate window. 

Uses and Variations
You can incorporate this function in other program modules and use it in expressions. For example, entering =Startup_Dir as the OnClick property of a button on a form returns the startup folder of Access whenever the button is clicked.

NOTE: You can change the MSACCESS.EXE argument for the Windows API GetModuleHandle function so that the function returns the startup folder of another program started in the Windows environment. Furthermore, you can pass a program name as a variable to the Windows API function, giving even more flexibility to the function.

Keywords: kbhowto kbprogramming KB210192

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.