Computer Tips

Browse for a File in Microsoft Access

Do you need your users to easily find a file using the Microsoft common dialog?

Tired of having to include an extra control on your form?

Use the new FileDialog object in Access XP:

Dim fd As FileDialog ' Declare the file dialog object
Dim vrtSel As Variant ' Declare a variant to be used to save the file name

Set fd = Application.FileDialog(msoFileDialogFilePicker) 'Establish a pointer to
                    the file picker
With fd
    .AllowMultiSelect = False ' Allows you to specify whether or not multiple
                                       files can be selected
    .Title = "Select Data File" 'Set the title for the dialog box
    .Filters.Add "Database Files", "*.mdb" ' Provide the type of files the user
                                                        can select
    If .Show Then 'Show the dialog
        For Each vrtSel In .SelectedItems 'scroll through the selected items
            Me.flDataFile = vrtSel 'extract the file name
        Next
    End If
End With
Set fd = Nothing