Function selectFile() Dim fd As FileDialog Set fd = Application.FileDialog(msoFileDialogFilePicker) With fd If .Show Then selectFile = .SelectedItems(1) Else 'stop execution if nothing selected End End If End With Set fd = Nothing End Function Private Sub Command0_Click() On Error GoTo ErrorHandler 'disable ms access warnings DoCmd.SetWarnings False 'Delete existing data in table 'This is optional. If you are combining spreadsheets 'in your table, don't run this query 'DoCmd.RunSQL "DELETE * FROM names" 'load spreadsheet DoCmd.TransferSpreadsheet acImport, 8, "tblCapacity", selectFile(), True MsgBox "Import Successful" 're-enable ms access warnings DoCmd.SetWarnings True Exit Sub ErrorHandler: MsgBox "There was an Error: " & Err & ": " & Error(Err) End Sub
Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.
”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.