I have a splitform where I want a button to choose and import a file into a table.
I have something like this:
Private Sub Command287_Click()
With Application.FileDialog(msoFileDialogOpen)
.Filters.Clear
.Filters.Add "Excel Files", "*.xlsx,*.xls"
.Filters.Add "Access Databases", "*.accdb"
.FilterIndex = 1 'Excel Files
.AllowMultiSelect = False
.ButtonName = "Open"
.InitialFileName = "C:\"
.Title = "Select a File to Import"
.InitialView = msoFileDialogViewDetails
If .Show Then
DoCmd.TransferSpreadsheet acImport, , "Data", .SelectedItems(1), True, "Data!"
End If
End With
End Sub
I set the reference to Microsoft Office 16.0 Object Library.
When I tried using this button there was this error:
Method 'FileDialog' of object '_Application' failed.