I have a public function that imports a file and runs some queries to do some work on the data. To check and see if I have already imported that file I run
If DCount("*", "qryImport_FindMatchingBIV") < 1 Then
CurrentDb.Execute "qryImport_AppendBIV", dbFailOnError
Else
MsgBox "This Invoice has already been imported"
Set qdf = Nothing
Set MyObject = Nothing
Set MySource = Nothing
Set MyFile = Nothing
Set wrk = Nothing
Set db = Nothing
DoCmd.Close acTable, "tbl_import", acSaveNo
Shell "C:\WINDOWS\explorer.exe """ & "E:\RepairsDatabase\BRCData\Import\Shop" & "", vbNormalFocus
Exit Function
End If
Everything works fine if the file has not been imported. If it has been imported it also works fine and gives me the message "This Invoice has already been imported"
However, If i try to import another file after that it fails and gives the error:
An unexpected error has occurred.
Please contact your System Administrator with this information.
Procedure Name: ImportFiles
Step: Importing Data
Error Number: 3008
Error Description: The table 'tbl_import' is already opened exclusively by another user, or it is already open through the user interface and cannot be manipulated programmatically.
And when i close the database it says
You attempted to open a database that is already opened by user 'Admin' on machine 'MachineName'. Try again when the database is available
if i close and open the database everything works fine again until i get a duplicate.
Any ideas on how I can get this table closed and get the function to exit cleanly?