Microsoft KB Archive/90861

= ACC: Connecting to the First Available Network Drive =

Article ID: 90861

Article Last Modified on 5/9/2003

-

APPLIES TO


 * Microsoft Access 1.0 Standard Edition
 * Microsoft Access 1.1 Standard Edition
 * Microsoft Access 2.0 Standard Edition

-



This article was previously published under Q90861



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 &quot;Introduction to Programming&quot; manual in Microsoft Access version 1.x, or the &quot;Building Applications&quot; manual, Chapter 3, &quot;Introducing Access Basic,&quot; 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.

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

     '-- Option Explicit

Declare Function GetDriveType% Lib &quot;kernel&quot; (ByVal nDrive%) Declare Function WNetAddConnection% Lib &quot;User&quot;(ByVal lpszNetPath$,_                                                   ByVal lpszPassword$,_                                                    ByVal lpszLocalName$) '--                         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) + &quot;:&quot;

'Substitute the appropriate server share and password. Results% = WNetAddConnection(&quot;\\server\share&quot;, &quot;password&quot;, _                                      FirstFreeDrive) End Function 

