Hello,
I have an import data button which creates a temp table in MS Access to import new data into and then runs an append query to add the data into a linked SQL Server table (the back end).
I then need some code to delete the temp table, because it is re-created each time a user clicks the import button. I'm getting a run time error 7874 though.
It's recognising the DoCmd.Close command but not recognising the DoCmd.DeleteObject command line. It's throwing a run time error 7874 MS Access can't find object 'TblTemp_Table' even though the table definitely still exists, I've just closed it. My code is:
Why is it throwing this run-time error when the temp table still exists? It is definitely named correctly.
I have an import data button which creates a temp table in MS Access to import new data into and then runs an append query to add the data into a linked SQL Server table (the back end).
I then need some code to delete the temp table, because it is re-created each time a user clicks the import button. I'm getting a run time error 7874 though.
It's recognising the DoCmd.Close command but not recognising the DoCmd.DeleteObject command line. It's throwing a run time error 7874 MS Access can't find object 'TblTemp_Table' even though the table definitely still exists, I've just closed it. My code is:
Code:
Private Sub cmdImportFilterResults_Click()
Dim sExcelFile As String
Dim fDialog As Office.FileDialog
Dim varFile As Variant
Set fDialog = Application.FileDialog(msoFileDialogFilePicker)
With fDialog
'Allow user to make multiple selections in dialog box
.AllowMultiSelect = False
'Set the title of the dialog box
.Title = "Please select a file"
'Show the dialog box. If the .Show method returns True, the user picked at least one file.
If .Show = True Then
sExcelFile = .SelectedItems(1)
'' import the file to the linked sql server table
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel12Xml, "Table_FilterResult", sExcelFile, True
DoCmd.OpenQuery ("qryAppendFilterResult")
DoCmd.Close acTable, "Table_FilterResult"
DoCmd.DeleteObject , "Table_FilterResult"
End If
End With
End Sub
Why is it throwing this run-time error when the temp table still exists? It is definitely named correctly.