ACC: How to Determine Startup Folder (Directory) of a ProgramLast reviewed: August 28, 1997Article ID: Q140909 |
The information in this article applies to:
SUMMARYAdvanced: Requires expert coding, interoperability, and multiuser skills. 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 (directory) 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. This article assumes that you are familiar with Visual Basic for Applications and with creating Microsoft Access applications using the programming tools provided with Microsoft Access. For more information about Visual Basic for Applications, please refer to your version of the "Building Applications with Microsoft Access" manual. NOTE: Visual Basic for Applications is called Access Basic in Microsoft Access version 2.0. For more information about Access Basic, please refer to the "Building Applications" manual.
MORE INFORMATIONThe CurDir() function returns the current folder. Because you can start Microsoft 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 Microsoft Access 7.0 and 97
In Microsoft Access 2.0NOTE: In the following sample code, an underscore (_) is used as a line-continuation character. Remove the underscore from the end of the line when re-creating this code in Access Basic.
Uses and VariationsYou can both 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 Microsoft 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 : kbprg PgmApi PgmHowTo MdlGnrl Version : 2.0 7.0 97 Platform : WINDOWS Hardware : x86 Issue type : kbhowto |
================================================================================
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |