Dialog Box help

garyholc

Registered User.
Local time
Today, 00:18
Joined
Jul 15, 2008
Messages
64
Hi

I'm trying to store the location of a file chosen by the user using the file chooser dialogue box. This code is taken from Microsoft. However, the MS code shows it for a list box. I just want it to store 1 file location in 1 field, called FileList.

Here is the code: The bit is red is the part I have changed to return the filename. However, instead of returing the filename/path it returns "FileDialog(msoFileDialogFilePicker)" in the field.

How do I get the actual path & filename returned into the field?

Thanks
Gary



Private Sub cmdFileDialog___Click()
' This requires a reference to the Microsoft Office 11.0 Object Library.
Dim fDialog As Office.FileDialog
Dim varFile As Variant
' Set up the File dialog box.
Set fDialog = Application.FileDialog(msoFileDialogFilePicker)
With fDialog

' Set the title of the dialog box.

.Title = "Select File"
' Clear out the current filters, and then add your own.
.Filters.Clear
.Filters.Add "Access Databases", "*.MDB"
.Filters.Add "Access Projects", "*.ADP"
.Filters.Add "All Files", "*.*"
' 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.

If .Show = True Then
Me.FileList = .Item
Else
MsgBox "You clicked Cancel in the file dialog box."
End If
End With

End Sub
 
Hi

Many thanks, yes this works great . Quick question if I may .... the form I will be using is the fFindOpenImportFile. When i click browse, this goes straight to the C:\Windows folder - is there a way to specify an alternative default location?

Many thanks
Gary
 
Just look at the code for that button to find the line where you specify your default location.
 
Sorry, was being thick! Found it straight away! lol.

Anyway, much appreciated for your help. :)

Gary
 

Users who are viewing this thread

Back
Top Bottom