Option Compare Database
Option Explicit
Public Enum FileType
Access = 0
Excel = 1
End Enum
Public Function SelectSingleFile(strCurDir As String, strDialogTitle As String, intFilter As FileType) As String
' Hetzelfde als SelectOneFile maar dan met behulp van de built-in Application.FileDialog.
On Error GoTo Err_SelectSingleFile
Dim fd As FileDialog
Dim varSelectedItem As Variant
Dim strFile As String
'Create a FileDialog object as a Folder Picker dialog box.
Set fd = Application.FileDialog(msoFileDialogFilePicker)
strFile = ""
With fd
.Title = strDialogTitle
.ButtonName = "&Select"
.InitialView = msoFileDialogViewDetails
'Add a filter that includes MDB or XLS files and make it the first item in the list.
.Filters.Clear
Select Case intFilter
Case FileType.Access
.Filters.Add "Access databases", "*.mdb", 1
Case FileType.Excel
.Filters.Add "Excel spreadsheet", "*.xls", 1
End Select
.Filters.Add "Alle bestanden", "*.*", 2
'Sets the initial file filter to number 1.
.FilterIndex = 1
If .Show = -1 Then
For Each varSelectedItem In .SelectedItems
If Len(strFile) > 0 Then
strFile = strFile & "|" & varSelectedItem
Else
strFile = varSelectedItem
End If
Next varSelectedItem
Else
strFile = ""
End If
End With
SelectSingleFile = strFile
Set fd = Nothing
Exit_SelectSingleFile:
Set fd = Nothing
Exit Function
Err_SelectSingleFile:
ErrorProc Err, Error$, "SelectSingleFile", "basFileDialog"
Resume Exit_SelectSingleFile
End Function