In access I have implemented a routine that allows the user to choose an image file in a subfolder of the application folder. The routine was achieved as follows:
Public Function FotoOpen(DirStart As String, SubDir As String) As String
' Questa procedura apre il file dialog per la selezione della foto
Dim PathDir As String
PathDir = DirStart
If SubDir <> "" Then
PathDir = PathDir & "\" & SubDir & "\"
End If
' Dim fDialog As Office.FileDialog
Dim Fp As Office.FileDialog
Set Fp = Application.FileDialog(msoFileDialogFilePicker)
With Fp
.Title = "Selezionare file immagine"
.ButtonName = "Conferma"
.InitialView = msoFileDialogViewPreview
.Filters.Clear
.Filters.Add "Tutti i Files (*.*)", "*.*"
.Filters.Add "Images Files (*.jpg)", "*.jpg" '
.Filters.Add "Images Files (*.bmp)", "*.BMP"
.Filters.Add "Images Files (*.png)", "*.png"
.Filters.Add "Images Files (*.ico)", "*.ico"
.FilterIndex = 2
.AllowMultiSelect = False
.InitialView = msoFileDialogViewPreview
.InitialFileName = PathDir
If .Show = -1 Then
FotoOpen = CStr(.SelectedItems.Item(1))
Else
Beep
' MsgBox "La selezione è stata annullata", vbInformation, "Informazione"
End If
End With
Set Fp = Nothing
End Function
But The Dialog doesn't seem to take into account the initial Dir passed, but it always opens on the Documents folder. Where's the mistake? Thank you all.