Link to home
Start Free TrialLog in
Avatar of psabourin
psabourin

asked on

Create a browse button

I would like to create a browse button or something similar.  I want to display the files located at t:\somedir which is on a network drive.  I want the user to click a file name and have the path and file name displayed on a form.  Is this possible?  If so, please let me know how.
Thanks
Avatar of Lesand
Lesand

If you have the Microsoft Common Dialog Active X Control installed you could use the Open File dialog box to capture the file name and pathby using the familiar Microsoft Open File browse method.

Instructions:
Insert the Common Dialog Control on your form in design view.  Name it CommonDialog1.  
Insert a command button on the form and call it cmdGetFileName.
Insert a text box named txtFileNameAndPath.

Then, in the OnClick event of the command button, put the following code:

' Call MS Common Dialog Box and set properties
    With Me!CommonDialog1
        .CancelError = True                 ' Set CancelError is True
        .Filter = "All Files(*.*)|*.*"      ' Set filters
        .FilterIndex = 2                    ' Specify default filter
        .ShowOpen                           ' Display the Open dialog box
    End With

' Display name of selected file
    Me!txtFileNameAndPath = Me!CommonDialog1.Filename

Now, when you click on the command button, the open file dialog box appears.    Find your file and click on Open and the file name should be displayed in the text box.

Avatar of psabourin

ASKER

Sorry, I am using Access 2.0.  I do not have Active X in this version.
This would probably be an excellent answer but I forgot to mention that I am using Access 2.0.  Therefore, I would not be able to use any of the ActiveX controls.  Can I still do my request in Access 2?
ASKER CERTIFIED SOLUTION
Avatar of wrussell051197
wrussell051197

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I tried inserting the activex control but it says im not licensed?
Create a form with a list box and insert the following code in the on open event

Private Sub Form_Open(Cancel As Integer)

Dim strFileName As String
Dim strRowSource As String
Dim strSourceFolder As String

strSourceFolder = YourFolderPath

strFileName = Dir(strSourceFolder)
   
While strFileName <> ""

    strRowSource = strRowSource & strFileName & ";"

    strFileName = Dir
   
Wend

strRowSource = Left(strRowSource, Len(strRowSource) - 1)

Me.ListBoxName.RowSourceType = "Value List"
Me.ListBoxName.RowSource = strRowSource

End Sub