Hi,
"tbl4_" is a spreadsheet in my Excel
So, I saw that I hadn't defined the variables I used, so I added to the code.
Now I'm not getting an error code.
But, I don't have the table I want the data from Excel to go to in Access.
I want to create a new table.
I think my code only allows for appending at the moment and I don't know how get it to upload a new table.
Code:
'Name macroSub Upload_PPNBench()
'Define strTable type: Access Table that will be uploaded
Dim strTable As String
'Define strFilePath type: Path to Excel .xls that will be uploaded into Access
Dim strFilePath As String
'Opens browse computer application
With Application.FileDialog(msoFileDialogFilePicker)
'Select one file at a time
.AllowMultiSelect = False
'Browser Title
.Title = "Locate a Excel file to Import"
'Name what the button command will do: Imports Excel file to Access
.ButtonName = "Import"
'Clear previous selection
.Filters.Clear
'Browser only works with .xls files, add ".xls" to Excel file
.Filters.Add "Excel", "*.xls"
'Location Browser begins
.InitialFileName = "C:\Test"
'Define Browser vie: thumbnail
.InitialView = msoFileDialogViewThumbnail
'If nothing is selected, have error sign appear
If .Show = -1 Then
Exit Sub
'If file is selcted, do following
End If
'Save the first file selected
strFilePath = Trim(.SelectedItems(1))
End With
'Define strTable as what table in Access
strTable = "tbl4_PNNBench"
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel12, strTable, strFilePath, True, "tbl4_Upload_PPNBench"
End Sub