ACC2: Sample Function for a Directory-Selection Dialog Box (128886)



The information in this article applies to:

  • Microsoft Access 2.0

This article was previously published under Q128886

SUMMARY

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

This article demonstrates how to create a sample user-defined Access Basic function that you can use to provide users with a directory-selection dialog box. This method is similar to the Open file common dialog box that can be called from Access Basic.

This sample function is based on the directory-selection function used by the Microsoft Access Developer's Toolkit (ADT) Setup Wizard. It requires that the SWU2016.DLL file be located in the Microsoft Access directory or, if the sample function is used with a Microsoft Access run-time application, that the SWU2016.DLL file be located in the same directory as the MSARN200.EXE file.

You can ship the SWU2016.DLL file with a Microsoft Access application, but it is only available when you install the ADT. It is copied to the Access directory during ADT Setup. This file is not available from Microsoft Access Product Support Services. Because this is a support file included with the ADT, it is subject to change in future versions of the product.



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 about Access Basic, please refer to the "Building Applications" manual.

MORE INFORMATION

To create a directory-selection dialog box on a form, follow the steps below.
  1. Open a database for which you want to create a directory-selection dialog box.
  2. Create a new module and add the following line to the Declarations section.

    NOTE: In the following sample code, an underscore (_) at the end of a line is used as a line-continuation character. Remove the underscore from the end of the line when re-creating this code.
          Declare Function zws_BrowseDir Lib "SWU2016.DLL" Alias "#2"_
          (ByVal hwnd As Integer, ByVal szTitle As String, ByVal szDir_
          As String) As Integer
    						
  3. Create a new form and add a text box called "ChosenDir."
  4. Add a command button to the form and then add the following code to the command button's OnClick event procedure.

    NOTE: In the following sample code, an underscore (_) at the end of a line is used as a line-continuation character. Remove the underscore from the end of the line when re-creating this code.
          Sub commdir_Click ()
    
          On Error GoTo SelectDir_Err
              Dim stDir As String
              Dim iTmp As Integer
              Dim stControl As String
              stControl = "ChosenDir"
    
              stDir = Trim$(IIf(IsNull(Me(stControl)), "", Me(stControl)))
    
              stDir = stDir & Chr$(0) & Space$(255)
    
               If zws_BrowseDir(Me.hwnd, "select directory", stDir) <> 0 Then
                  stDir = Left(stDir, InStr(stDir, Chr$(0)) - 1)
                  Me(stControl) = stDir
              End If
    
              Exit Sub
    
          SelectDir_Err:
              If Err = 53 Then 'File not found.
                  MsgBox "Could not load 'SWU2016.DLL', make sure file _
                  exists", 48
              Else
                  MsgBox Error$ & Chr(13) & Chr(10) & " ErrorNum:" _
                  & Str(Err), 48
              End If
              Exit Sub
    
          End Sub
    						
  5. View the form in Form view.
  6. Choose the command button and then use the directory-selection dialog box to select a directory name. The directory name you select appears in the ChosenDir text box.

Modification Type:MajorLast Reviewed:11/6/2000
Keywords:kbinfo kbusage KB128886