Private Sub cmdImport_Click()
Dim strPathFile As String
Dim strTable As String, strBrowseMsg As String
Dim strFileName As String, strInitialDirectory As String
Dim blnHasFieldNames As Boolean
Dim dlgPicker As FileDialog
Dim vrtSelectedItem As Variant
blnHasFieldNames = True
strBrowseMsg = "Select the EXCEL file:"
strInitialDirectory = "F:\COE-Database\"
Set dlgPicker = Application.FileDialog(msoFileDialogFilePicker)
With dlgPicker
.Title = strBrowseMsg 'De titel voor het venster
.InitialFileName = strInitialDirectory 'Waar moet het venster beginnen?
.InitialView = msoFileDialogViewList 'Bepaal weergave
With .Filters
.Clear
.Add "Microsoft Excel", "*.xls; *.xlt", i + 1 'Beperk de bestandstypes tot .xls
End With
.FilterIndex = 1
'**************************************************************************
' Variant voor één bestand
'**************************************************************************
.AllowMultiSelect = False 'Slechts één bestand kiezen.
If .Show = -1 Then 'Bepaal of gebruiker op OK-knop heeft geklikt.
strFileName = .SelectedItems.Item(1) 'String wordt gevuld met geselecteerde bestand
Else
MsgBox "Er is op <Cancel> gedrukt..."
End If
'' '**************************************************************************
'' ' Variant voor meerdere bestanden
'' '**************************************************************************
'' .AllowMultiSelect = True 'meerdere bestanden kiezen.
'' If .Show = -1 Then 'Bepaal of gebruiker op OK-knop heeft geklikt.
'' For Each vrtSelectedItem In .SelectedItems
'' strFileName = strFileName & vrtSelectedItem & ";"
'' Next
'' Else
'' MsgBox "Er is op <Cancel> gedrukt..."
'' End If
End With
If strFileName = "" Then
MsgBox "No file was selected.", vbOK, "No Selection"
Exit Function
End If
strTable = "tablename"
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, _
strTable, strFileName, blnHasFieldNames
End Function