ACC: Connecting to the First Available Network Drive

Last reviewed: June 8, 1997
Article ID: Q90861
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.

To make a network connection with the Windows application programming interface (API), you can use an unused logical drive letter or a universal naming convention (UNC) name (\\SERVER\SHARE). You can call the Windows API function GetDriveType() from an Access Basic module to find the first available drive letter and then make a network connection to this available drive.

This article assumes that you are familiar with Access Basic and with creating Microsoft Access applications using the programming tools provided with Microsoft Access. For more information on Access Basic, please refer to the "Introduction to Programming" manual in Microsoft Access version 1.x, or the "Building Applications" manual, Chapter 3, "Introducing Access Basic," in version 2.0.

MORE INFORMATION

Use the following steps to find the first free drive and make a network connection:

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.

  1. Declare the following API functions in a module's Declarations section:

          '------------------------------------------------------------------
          Option Explicit
    

          Declare Function GetDriveType% Lib "kernel" (ByVal nDrive%)
          Declare Function WNetAddConnection% Lib "User"(ByVal lpszNetPath$,_
    
                                                        ByVal lpszPassword$,_
                                                        ByVal lpszLocalName$)
          '------------------------------------------------------------------
    
    

  2. Type the following function to return the first free drive and make the new connection:

          Function FreeDrive ()
    
             Dim DriveNum, FirstFreeDrive
             Dim FirstDrive%, Results%
    
             DriveNum = -1
    
             Do
                DriveNum = DriveNum + 1
                FirstDrive% = GetDriveType(DriveNum)
             Loop Until FirstDrive% = 0
    
             FirstFreeDrive = Chr$(DriveNum + 65) + ":"
    
             'Substitute the appropriate server share and password.
             Results% = WNetAddConnection("\\server\share", "password", _
                                           FirstFreeDrive)
          End Function
    
    

REFERENCES

Microsoft Access "Introduction to Programming," version 1.0, page 8


Keywords : kbprg PgmApi
Version : 1.0 1.10 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.