Microsoft KB Archive/128886

= ACC2: Sample Function for a Directory-Selection Dialog Box =

Article ID: 128886

Article Last Modified on 11/6/2000

-

APPLIES TO


 * Microsoft Access 2.0 Standard Edition

-



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.

 Open a database for which you want to create a directory-selection dialog box.  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  Create a new form and add a text box called "ChosenDir."  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  View the form in Form view. 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.</ol>

Keywords: kbinfo kbusage KB128886

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.