Set default folder for File Dialog

P

Pendragon

Access07

I've been using the following code successfully in many applications to open
a browser window for a user to select a file. However, in my current project
I have several different modules where users will be importing and linking to
files and each module should default the file dialog window to a specific
location. Is there a way to set the default location for the file dialog
window which does not reference the database default folder location?

Thanks in advance!

Dim fDialog As Office.FileDialog
Dim varFile As Variant

Me.FileList.ControlSource = ""

Set fDialog = Application.FileDialog(msoFileDialogFilePicker)
With fDialog
.AllowMultiSelect = False
.filters.Clear
.filters.Add "All Files", "*.*"

If .Show = True Then
For Each varFile In .SelectedItems
Me.FileList.AddItem varFile
Me.txtFileToLink.Value = varFile
If IsNull(Me.txtFileToLink) Then
Else
Me.txtFileToLink.SetFocus
End If
Next
Else
End If
End With

Exit Sub
 
R

RonaldoOneNil

Use the initial file name property

With fDialog
.InitialFileName = "C:\YourPathName\"
.AllowMultiSelect = False
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top