Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Storing a file patch from a common dialog box

Status
Not open for further replies.

marcin2k

Programmer
Jan 26, 2005
62
CA
Hello,

I am really lost, I am trying to think of a way I can make a user click a button and then basically a folder will open up and the user can select any file. When they select the file the path of that file will be saved in a textbox. Any ideas. Thanks

Martin
 
You can always use the FileDialog object:

Code:
With Application.FileDialog(msoFileDialogFilePicker)

   [green]' Allow user to make multiple selections in dialog box[/green]
   .AllowMultiSelect = True
            
   [green]' Set the title of the dialog box.[/green]
   .Title = "Please select one or more files"

   [green]' Set the intial file path[/green]
   .InitialFileName = "C:\"

   [green]' Clear out the current filters, and add our own.[/green]
   .Filters.Clear
   .Filters.Add "Access Databases", "*.MDB"
   .Filters.Add "Access Projects", "*.ADP"
   .Filters.Add "All Files", "*.*"

   [green]' Show the dialog box. If the .Show method returns True, the
   ' user picked at least one file. If the .Show method returns
   ' False, the user clicked Cancel.[/green]
   If .Show = True Then

      [green]'Loop through each file selected and print its path[/green]
      For Each varFile In .SelectedItems
         Debug.Print varFile
      Next

   Else
      MsgBox "You clicked Cancel in the file dialog box."
   End If
End With

This returns a collection, .SelectedItems, containing the paths to all selected files.

This code was slightly modified from Access help. None of the properties (.AllowMultiSelect, .InitialFileName, etc) are required and there are a few more. This will allow you to set the initial folder to select a file from and can even allow choosing more than one file. It does require a reference to "Microsoft Office X.0 Object Library" to work.

Hope this helps,
Tom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top