ACC: Sample Function to Determine the Access Startup DirectoryLast reviewed: June 6, 1997Article ID: Q88174 |
The information in this article applies to:
SUMMARYAdvanced: Requires expert coding, interoperability, and multiuser skills. This article describes the steps involved in creating a function that returns the Microsoft Access startup directory. Microsoft Access does not have a built-in command to return the Microsoft Access startup directory. However, you can accomplish this by making Windows application programming interface (API) calls in Access Basic. NOTE: Microsoft Access 2.0 does include the function SysCmd() to return the directory where the Msacess.exe file is located. See the bottom of this article for more information.
MORE INFORMATIONThe Access Basic CurDir$() function returns the current directory. Because Microsoft Access can be started from a directory other than the current directory or the current directory can be changed with the ChDir statement, the CurDir$() function cannot be used to determine the startup directory. The following sample program module makes use of the Windows API functions GetModuleHandle() and GetModuleFileName(). With the module handle, the path can be obtained with the GetModuleFileName() function.
Creating the ModuleThe following steps demonstrate how to create the sample Access Basic function that returns the startup directory:
Uses and VariationsThe Startup directory is displayed when you type the following line in the Immediate window:
? StartUp_Dir()This function can also be incorporated in other program modules and can be used in expressions. For example, entering =Startup_Dir() as the OnPush or OnClick property of a button on a form returns the startup directory of Microsoft Access whenever the button is chosen. NOTE: You can change the MSACCESS.EXE argument for the Windows API GetModuleHandle() function so that the function returns the startup directory 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.
SysCmd() FunctionIf all you need is the directory in which the Msacess.exe file is located, you can use the SysCmd() function, as in the following example:
Function test() Dim AccDir As String AccDir = SysCmd(acSysCmdAccessDir) Debug.Print AccDir End Function REFERENCES"Microsoft Windows Software Development Kit," Microsoft Press, 1992 "Programming Windows: the Microsoft Guide to Writing Applications for Windows 3," Charles Petzold, Microsoft Press, 1990 "Programmer's Reference Library: Microsoft Windows 3.1 Guide to Programming Reference," Volumes 1 - 6, Microsoft Press, 1992 |
Keywords : kbprg PgmApi
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |