FileDialog Not Working in Access 2010

If you're still having trouble, this is what I use. You must set a reference to Microsoft Office
Put this code into a module:
Function dialogFileBrowse() As String
'##### This function gives the user the facility to browse for a file and to be able to use the path
'##### as a destination.
'##### You must include the Microsoft Office Object Library, go to Tools/References
Dim fp As FileDialog
Dim vrtSelectedItem As Variant
Dim varX As String

'Create a FileDialog object as a File Picker dialog box.


Set fp = Application.FileDialog(msoFileDialogFilePicker)
fp.AllowMultiSelect = True
If fp.Show = -1 Then
'this is the only way I've been able to assign the selected path as a value to string variable
For Each vrtSelectedItem In fp.SelectedItems
varX = vrtSelectedItem

'vrtSelectedItem is a String that contains the file/path of each selected item.


Next vrtSelectedItem

End If

dialogFileBrowse = varX

End Function
This function should be called from where you set the file/path ie myFile=dialogFileBrowse

David
 
Re: FileDialog that Works in Access 2010

Thank you to everyone who contributed to this code that I put together for a 2010 application ... for picking one file from a specified folder

'create dialog
Dim f As Object
Set f = Application.filedialog(3)

Dim varFile As Variant
' my name for the file picked
Dim newFCL As String

With f
' Allow Mulitple Selections
. AllowMultiSelect = false

' Set the title of the dialog box. '
.Title = "Please select the file for the date selected"
' Sets folder to open
.InitialFileName = "c:\history"
' Clear out the current filters, and add our own.'
.Filters.Clear
.Filters.Add "Prices", "*.FCL"
End With '

' Call .Show and show the dialog. If the method returns True, the user picked at least one file.
' If the method returns False, the user clicked Cancel.

If f.Show Then
For Each varFile In f.SelectedItems
newFCL = varFile
Next
MsgBox newFCL & " copied to Z:\output\MthEndPrices.txt."
' do something with the file
FileCopy newFCL, "C:\output\NewPrices.txt"
Else
MsgBox "No file selected", 64, "CAT"
Exit Sub
End If
 
I'm trying to run the FileDialog in a 64-bit Windows Server 8 environment.

It errors out on Filters.Add. Anyone else experiencing this?
 

Users who are viewing this thread

Back
Top Bottom