Results 1 to 3 of 3
  1. #1
    tagteam is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2013
    Posts
    494

    After exiting Public Function next time i try i get error that the table is open

    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?

  2. #2
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    Try it without the acSaveNo
    DoCmd.Close acTable, "tbl_import", acSaveNo

    Apparently you are transferring into exclusive mode in the DB. Maybe it has to do with the edit command. However, I am not sure. It seems the Shell command is simply opening a folder. So, I don't think anything else is causing it.

  3. #3
    tagteam is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2013
    Posts
    494
    I was able to get around this by using an if statement.

    instead of trying to exit the function where it was i moved it up in the code execution flow to an earlier spot and then wrote an if statement and was able to break out of the code earlier if i needed and that resolved the problem.
    Thanks

Please reply to this thread with any new information or opinions.

Similar Threads

  1. VBA Can't find Public Function
    By GraeagleBill in forum Programming
    Replies: 15
    Last Post: 03-17-2016, 09:38 PM
  2. Replies: 4
    Last Post: 11-13-2014, 08:00 PM
  3. Function to open school with error
    By Ruegen in forum Forms
    Replies: 1
    Last Post: 09-03-2014, 10:12 PM
  4. Replies: 18
    Last Post: 10-02-2013, 10:26 AM
  5. VBA code exiting no error.
    By Jmeyering in forum Programming
    Replies: 1
    Last Post: 11-12-2012, 04:29 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums