calvarado536
Technical User
I have a code set up on access that opens a select file dialog box and that with the selected file it imports it into a certain table. How do I get it to allow me to select multiple files and import all of the files selected. I know it's probably a simple fix but I can't seem to get it. I know I most likely have to change the allowmultiselect to true and i've tried that and it didn't work with the multiple files I selected. It only imported 1 file. Thank you in advance for the help!
Code:
Public Function file_Upload()
On Error GoTo ErrorHandler
Dim fd As Office.FileDialog
Dim varSelectedItem As Variant
Dim strFileNameAndPath As String
Set fd = Application.FileDialog(msoFileDialogFilePicker)
With fd
.AllowMultiSelect = False
.Title = "Select Most Recent file"
.ButtonName = "Select"
.Filters.Clear
.Filters.Add "File Type", "*.xls; *.xlsx; *.xlsm", 1
.InitialView = msoFileDialogViewDetails
.InitialFileName = "C:\reports\"
If .Show = -1 Then
strFileName = .SelectedItems(1)
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel8, "table name", strFileName, True
Else
Debug.Print "User pressed Cancel"
strFileNameAndPath = ""
End If
End With
SelectXLFile = strFileNameAndPath
ErrorHandlerExit:
Set fd = Nothing
Exit Function
ErrorHandler:
MsgBox "Error No: " & Err.Number _
& " in SelectXLFile procedure; " _
& "Description: " & Err.Description
Resume ErrorHandlerExit
End Function