Since my research has led me to belief that my references could have something to do with it ,here my references to my MS Access:
My problem is I'm trying to merely call up a file dialog as a function with the return being the string path chosen. I start of with
Dim fd as filedialog
Set fd = Application.filedialog(msoFileDialogSave)
With fd
...
Now, the decision with the dim is fine, but the "set" line gives an error saying that the method filedialog for the object "_application" is unsuccessful.
I've looked at similar problems here, but with no success. I expected to achieve my goals
You can use this code:
Dim f As Office.FileDialog
Dim varItem As String
Set f = Application.FileDialog(msoFileDialogFilePicker)
With f
.Title = "My Title"
.AllowMultiSelect = False 'or true
.ButtonName = "Select" 'give any name
.Filters.Clear 'clear filter before set new ones
.Filters.Add "Excel files", "*.xl*" 'then create new ones
.Filters.Add "Word files", "*.do*"
.Filters.Add "Access files", "*.mdb; *.accdb"
.FilterIndex = 2 'pre-select one filter
.InitialFileName = "D:\" 'start directory
If .Show Then
' In case of Multiselect use this code
For Each varItem In f.SelectedItems
Debug.Print varItem
Next varItem
' In case of no MultiSelect use this code
SelectedFileName = f.SelectedItems(1)
Else
' User selected cancel
EndIf
End With
End Function
Additional options:
Need reference to "Microsoft Office Object Library"