I am using VBA code in Access 2000 to import a user-defined spreadsheet into the database. This is working great except the Excel instance does not close. When the user then tries to move or delete that Excel file they receive a message that the file is still in use. Currently the only way for the user to get around this is to use Ctrl-Alt-Delete and then kill the Excel instance from the Processes list. I have tried several different properties and methods of the Excel object but have not been able to close the instance. My code is as follows:
Any Ideas?? Thanks
Code:
On Error GoTo cmdImport_err
Dim strTable As String
Dim strPath As String
Dim xl As Excel.Application
Dim strSQL As String
Dim strType As String
strTable = "EssayGrades_temp"
Set xl = New Excel.Application 'instantiate Excel
xl.Dialogs(xlDialogFindFile).Show
strPath = xl.ActiveWorkbook.FullName
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, strTable, strPath, -1
xl.Application.Quit
Set xl = Nothing
cmdImport_err:
If Err.Number = -2147217900 Then
MsgBox "You have attempted to insert duplicate data. Please make sure you have not imported the same file twice.", vbExclamation, "Duplicate Data"
GoTo ErrRecover
Else
MsgBox Err.Description & "An error occured while attempting to import the file."
GoTo ErrRecover
End If