ACC2000: How to Determine Startup Folder of a Program

ID: Q210192


The information in this article applies to:
  • Microsoft Access 2000

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

This article applies to a Microsoft Access database (.mdb) and 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 (<Drive:>\<Path>\) 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, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft support professionals 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 needs. If you have limited programming experience, you may want to contact a Microsoft Certified Solution Provider or the Microsoft fee-based consulting line at (800) 936-5200. For more information about Microsoft Certified Solution Providers, please see the following page on the World Wide Web:

http://www.microsoft.com/mcsp/
For more information about the support options available from Microsoft, please see the following page on the World Wide Web:

http://www.microsoft.com/support/supportnet/overview/overview.asp


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.

  1. 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.


  2. Type the following procedure:


  3. 
    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
     
  4. 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.

Additional query words:

Keywords : kbprg kbdta AccCon MdlGnrl
Version : WINDOWS:2000
Platform : WINDOWS
Issue type : kbhowto


Last Reviewed: July 6, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.