ACC: Sample Function to Find File Associations

Last reviewed: June 8, 1997
Article ID: Q109931
The information in this article applies to:
  • Microsoft Access versions 1.0, 1.1, 2.0

SUMMARY

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

This article demonstrates a sample Access Basic function that you can use to obtain the executable file name associated with a document file name by calling the Microsoft Windows API function FindExecutable().

MORE INFORMATION

The following sample function requires a path string parameter and a file name string parameter. The function returns the path of the associated file.

NOTE: 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.

   ' *** Declarations Section ***
   Option Explicit

   Declare Function FindExecutable% Lib "Shell" (ByVal lpszFile$, _
      ByVal lpszDir$, ByVal lpszResult$)

   Function GetAssociation (Path As String, FileName As String)
      Dim Result As String, X As Integer
      Result = Space$(256)
      X = FindExecutable(FileName, Path, Result)
      GetAssociation = Result
   End Function

To find the path and name of the executable file associated with a file called MYDB.MDB that is located in the root directory on the D drive you could type the following in an Immediate window:

   ? GetAssociation ("D:\", "MYDB.MDB")

The function would return

   D:\ACCESS.100\MSACCESS.EXE

if the MYDB.MDB file was associated with the MSACCESS.EXE executable file located in the ACCESS.100 directory on the D drive.

REFERENCES

Microsoft Windows Software Development Kit "Programmer's Reference, Volume 2: Functions," Version 3.1, pages 303-305


Keywords : kbprg PgmApi
Version : 1.0 1.1 2.0
Platform : WINDOWS
Hardware : X86
Issue type : kbinfo


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: June 8, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.