Results 1 to 14 of 14
  1. #1
    robs23 is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Apr 2014
    Posts
    109

    "You do not have exclusive access to the database.." error

    Hi Guys,



    I'm getting an error that reads:

    Code:
    You do not have exclusive access to the database at this time. If you proceed to make changes, you may not be able to save them later
    I'm usually getting this error after running a code that withdraws some data of back end table. During the code's performance I open several recordsets (both based on front end and back end data) and close objects at code's end. I read somewhere that this error might have something to do with opening and closing connection to database many times, but I don't think it's the case. In my other file I have lots of similar codes also withdrawing data from back end and I've never encountered this error.. Let me also add that both front and back end are on my local drive, so there's no chance someone might have them open. I checked "Clients settings" and I open database in shared mode with no locks at default.. What might be wrong?
    BTW, when I press ok on this error and run my code again (without restarting the db) I sometimes get error 3734 when code reaches the line:
    Code:
    Set db = CurrentDb
    Error 3734 reads:
    Code:
    The database has been placed in a state by user 'ADMIN'
    on machine 'XXX' that prevents it from being opened
    or locked

  2. #2
    burrina's Avatar
    burrina is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Freeport,Texas
    Posts
    1,383
    Try deleting the ldb file. Is the db on a network drive?
    Dim db As DAO.Database

    Set db = CurrentDb
    HTH

  3. #3
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    The error you are getting usually means that the changes you are trying to make are not changes to the data, but changes to database objects such as tables or forms, while there are two copies of the database open. For example, if you have the back end and the front end open at the same time, and try to modify a table structure, you may see this error.

    Another possibility is that there is a "hidden" MSACCESS process running (often due to an abnormal exit). With all your databases closed, start Windows Task Manager (Ctrl-Alt-Del), click the "Processes" tab, and look for MSACCESS.EXE in the list - if there is one, click "End Process" to force it to terminate.

  4. #4
    robs23 is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Apr 2014
    Posts
    109
    @burrina Both FE and BE are on local drive (no external access possible). Can't delete .ldb file while I have my database open.

    @John_G I kind of have BE and FE open at the same time - I use
    OpenDatabase(db location)
    in my code and then close it at the code's end. I don't change data structure, however, only data itself. At the FE start I use
    DoCmd.TransferDatabase
    to copy 2 tables from BE to FE but I don't suppose it might be meaningful.. I even checked it by disabling this part of code but I'm getting the same error..
    Below is my code, maybe you'll be able to find the error I'm overlooking.. I get the error when i run "MainScript" (it calls other functions and subs during its performance)

    Code:
    Public Function dependentSteps(product As Long, step As Long) As Long()'zwraca tablice wszystkich krokow zaleznych, ktore spelniaja warunek:
    '- nie sa jeszcze ZAKONCZONE
    '-nie sa jeszcze AKTYWNE
    '-sa zalezne od kroku "step"
    
    
    Dim chosenSteps() As Long
    Dim rs As DAO.Recordset
    Dim index As Long
    Dim db As DAO.Database
    ReDim chosenSteps(1) As Long
    Set db = OpenDatabase(backEndPath)
    Set rs = db.OpenRecordset("SELECT * FROM tbProductSteps WHERE productId = " & product & " AND isFinished = False AND isActive = False")
    If Not rs.EOF Then
        rs.MoveFirst
        Do Until rs.EOF
            If isDependent(step, rs.Fields("stepId")) Then
                index = UBound(chosenSteps)
                ReDim Preserve chosenSteps(index + 1)
                chosenSteps(index + 1) = rs.Fields("stepId")
            End If
            rs.MoveNext
        Loop
    End If
    
    
    dependentSteps = chosenSteps()
    rs.Close
    db.Close
    Set rs = Nothing
    Set db = Nothing
    End Function
    
    
    Public Function superiorSteps(product As Long, step As Long) As Long()
    'zwraca tablice wszystkich krokow nadrzednych, ktore spelniaja warunek:
    '- nie sa jeszcze ZAKONCZONE
    '-nie sa jeszcze AKTYWNE
    '-sa nadrzedne do kroku "step"
    
    
    Dim chosenSteps() As Long
    Dim rs As DAO.Recordset
    Dim index As Long
    Dim db As DAO.Database
    ReDim chosenSteps(1) As Long
    Set db = OpenDatabase(backEndPath)
    Set rs = db.OpenRecordset("SELECT * FROM tbProductSteps WHERE productId = " & product & " AND isFinished = False AND isActive = False")
    If Not rs.EOF Then
        rs.MoveFirst
        Do Until rs.EOF
            If isDependent(rs.Fields("stepId"), step) Then
                index = UBound(chosenSteps)
                ReDim Preserve chosenSteps(index + 1)
                chosenSteps(index + 1) = rs.Fields("stepId")
            End If
            rs.MoveNext
        Loop
    End If
    
    
    superiorSteps = chosenSteps()
    rs.Close
    db.Close
    Set rs = Nothing
    Set db = Nothing
    
    
    End Function
    
    
    Public Function isDependent(SuperiorStep As Long, InteriorStep As Long) As Boolean
    Dim db As DAO.Database
    Set db = CurrentDb
    Dim rs As DAO.Recordset
    Set rs = db.OpenRecordset("SELECT * FROM tbStepDependenciesBp WHERE Step = " & InteriorStep & " AND dependentOfStep = " & SuperiorStep)
    
    
    If rs.EOF Then
    isDependent = False
    Else
    isDependent = True
    End If
    rs.Close
    Set rs = Nothing
    db.Close
    Set db = Nothing
    End Function
    
    
    Public Function isExclDependent(product As Long, SuperiorStep As Long, InteriorStep As Long) As Boolean
    Dim i As Long
    Dim counter As Long
    Dim checkSteps() As Long
    counter = 0
    checkSteps = superiorSteps(product, InteriorStep)
    
    
    For i = 2 To UBound(checkSteps)
    'sprawdz wszystkie kroki nadrzedne
    If Not checkSteps(i) = SuperiorStep Then
        counter = counter + 1
    End If
    Next i
    
    
    If counter = 0 Then
    isExclDependent = True
    Else
    isExclDependent = False
    End If
    End Function
    
    
    Sub mainScript()
    Dim i As Integer
    Dim product As Long
    Dim step As Long
    Dim str As String
    Dim time1 As Date
    Dim time2 As Date
    
    
    Dim chosen() As Long
    Dim superiors() As Long
    time1 = Time
    backEndName = "npdmanager_be.accdb"
    backEndPath = "C:\Users\robert.roszak\Desktop\Projekty zawodowe\Access\NPDs\" & backEndName
    step = 6
    product = 25
    chosen = dependentSteps(product, step)
    str = "Możesz potwierdzić kroki "
    For i = 2 To UBound(chosen)
        superiors = superiorSteps(product, chosen(i))
        For n = 2 To UBound(superiors)
            If isExclDependent(product, superiors(n), chosen(i)) Then
                str = str & ", " & chosen(i)
            End If
        Next n
    Next i
    time2 = Time
    
    
    MsgBox str & vbNewLine & "Koniec w " & Format(time2 - time1, "Hh:Nn:Ss")
    End Sub

  5. #5
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    Hi -

    I don't see anything obvious. Since your dabase name and database path are hard coded (i.e. not variable), could you just link to the required tables, instead of explicitly opening and closing the other database?

    Are you able to determine which line in MainScript is causing the error?

  6. #6
    robs23 is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Apr 2014
    Posts
    109
    Hi

    It is always this way - then I first open the FE file and run "MainScript" it always performs as expected - no errors etc., it comes to an end and displays expected msgbox. When I press "Ok" on the msgbox and later try to change something in the "MainScript" (I usually try to modify line "step = 6"), Access displays "You do not have exclusive access.." error. When I close the prompt I'm still able to change this line and run "MainScript", but won't be able to save changes to FE afterwards. And after that error "MainScript" sometimes still is able to perform well, but sometimes gives the error 3734 at the line:

    Code:
    Public Function isDependent(SuperiorStep As Long, InteriorStep As Long) As Boolean
    Dim db As DAO.Database Set db = CurrentDb


  7. #7
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    Since you are getting that error when you try to modify MainScript, that is a sure indication that somehow your FE (assuming that is where MainScript is) is open twice. I can replicate the error by intentionally opening a database twice and then trying to modify a module.

    What happens if you try to modify MainScript before running it the first time?

    As I said, I see nothing in the code that might cause the error.

    Some of these sites might help:

    http://support.microsoft.com/kb/274211

    https://www.accessforums.net/program...cked-6783.html

  8. #8
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    I have see the following "rule of thumb" many times, but I think Allen states it best:
    If you open anything, close it.
    If you did not open it, do not close it.
    Regardless of whether you open it or not, set all object variables to Nothing.

    Allen Browne - Microsoft MVP. Perth, Western Australia.
    Tips for Access users - http://allenbrowne.com/tips.html
    I am going to cut out a lot of your code so my thinking is easier to follow.
    Looking at your code in this function, I see:
    Code:
    Public Function superiorSteps(product As Long, step As Long) As Long()
        Dim db As DAO.Database
        Dim rs As DAO.Recordset
    .
    .
       
        Set db = OpenDatabase(backEndPath)
        Set rs = db.OpenRecordset("SELECT * FROM tbProductSteps WHERE productId = " & product & " AND isFinished = False AND isActive = False")
     .
     .
     .
        rs.Close
        db.Close
        Set rs = Nothing
        Set db = Nothing
    End Function
    The database is opened, the recordset is opened
    the recordset is closed, the database is closed.
    All good. Follows the rule-of-thumb.

    Then, in this function:
    Code:
    Public Function isDependent(SuperiorStep As Long, InteriorStep As Long) As Boolean
        Dim db As DAO.Database
        Dim rs As DAO.Recordset
    
        Set db = CurrentDb
        Set rs = db.OpenRecordset("SELECT * FROM tbStepDependenciesBp WHERE Step = " & InteriorStep & " AND dependentOfStep = " & SuperiorStep)
    .
    .
    .
        rs.Close
        db.Close   '<<-remove/comment out this line
        Set rs = Nothing
        Set db = Nothing
    End Function
    This code does not follow the rule-of-thumb
    You DID NOT open the database - yet you CLOSED dB (which is Currentdb).
    "db" is a link (pointer) to the current database.You CLOSED the link to the current dB. (Not good) So the next time you try to execute the code, there is not a databse available. (MS has some misleading messages at times)

    All you should do is set the variable db to nothing.

    Change the code to comment out or remove the line db.Close in only this function, then run your code.

  9. #9
    robs23 is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Apr 2014
    Posts
    109
    @John_G Thanks for your pointer - I'll definitely check it and dig into sources when I have time.

    @ssanfu Thanks for you contribution, I wasn't aware this is called rule-of-thumb though more-less I applied to it anyway (just a matter of good practice). I removed that line but it didn't resolve the issue...

  10. #10
    robs23 is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Apr 2014
    Posts
    109
    OK, from provided threads I saw this issue might be related to the fact, that the db I open in the code (Set db = OpenDatabase(...)) is linked to some other front end. I connected it to newly created db (not linked to any other db) but it didn't solve the issue... I tried something else then. I changed the code not to use any external db but the current one (so Set db = CurrentDb INSTEAD OF Set db = OpenDatabase(..)) and then everything works as supposed to! So errors I'm getting are related to back end rather than front end (which is confusing as debugger underlines Set db = CurrentDb and I can't save changes to FE and not BE).
    How can I overcome this? Please find attached a .zip file with both front end and back end db so you could test it.

    Robert
    Attached Files Attached Files

  11. #11
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    Hi -

    Instead of explicitly (i.e. in your code) opening-closing the BE database all the time, try linking to the BE table.

    I just did that and the "not exclusive" error went away.

    John

  12. #12
    robs23 is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Apr 2014
    Posts
    109
    HI

    Doesn't it matter that that table is already linked to some other FE? Can table be linked to multiple FEs?

  13. #13
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    Hi -

    Can table be linked to multiple FEs?
    That is exactly what the splitting in FE - BE is designed for, i.e. so that multiple users, each with their own copy of the FE, can access the same tables in the BE.

    You should never have multiple users in the same network copy of the FE, though. That will lead to problems, sooner or later.

  14. #14
    robs23 is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Apr 2014
    Posts
    109
    Hi,

    I've just realized how silly my last question was Thanks for your input, I've changed it to linked table and now it works painless (and twice as fast!)

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

Similar Threads

  1. Replies: 2
    Last Post: 06-03-2014, 10:27 AM
  2. Replies: 1
    Last Post: 03-11-2014, 08:07 PM
  3. Replies: 1
    Last Post: 04-21-2013, 06:13 PM
  4. Replies: 7
    Last Post: 06-28-2012, 02:05 PM
  5. Replies: 2
    Last Post: 11-04-2011, 02:45 AM

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