ACC: Sample Function to Determine the Access Startup DirectoryID: Q88174
|
Advanced: 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.
The 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.
Option Explicit
Declare Function GetModuleHandle% Lib "kernel" (ByVal FileName$)
Declare Function GetModuleFileName% Lib "kernel" (ByVal hModule%, _
ByVal FileName$, ByVal nSize%)
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
? StartUp_Dir()
Note that the Microsoft Access startup directory is displayed 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.
Function test()
Dim AccDir As String
AccDir = SysCmd(acSysCmdAccessDir)
Debug.Print AccDir
End Function
"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
Additional query words:
Keywords : kbprg
Version : WINDOWS:1.0,1.1,2.0
Platform : WINDOWS
Issue type : kbhowto
Last Reviewed: July 13, 1999