Hi - I am trying to use the below code to import an Excel file into my access database, but I get the error
Run-time error '424':
Object required
On the line
Code:
For Each importPath In .SelectedItems
Maybe my code is not the best, but how can someone here recommend I set this up to allow the user to select ONE .csv or one .xls or one .xlsx file to import?
Code:
Function GetFile()
Dim sMyPath As FileDialog
Dim sPath As Variant
DoCmd.SetWarnings False
DoCmd.Hourglass True
Set sMyPath = Application.FileDialog(msoFileDialogFilePicker)
With sMyPath
.AllowMultiSelect = False
.Title = "Select your File"
.Filters.Add "All Files", "*.*"
If .Show = -1 Then
For Each sPath In .SelectedItems
DoCmd.TransferSpreadsheet acImport, "tblName", "Equipment", sPath, True
Next sPath
Else
MsgBox "Please pick a file to import"
End If
End With
DoCmd.SetWarnings True
DoCmd.Hourglass False
End Function