Results 1 to 7 of 7
  1. #1
    cebrower is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2018
    Location
    Spring Lake, MI
    Posts
    110

    Check to see if a table is in use


    We have a linked table that gets re-created once daily using a make table query followed by several update queries. Unfortunately, that table is used as a data source for several forms. If a user has one of those forms open the make table query fails. Is there a way in VBA to determine if that table is in use prior to running the make table query and maybe even to know which users have a form open that uses that table as a data source?

  2. #2
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,977
    Hi
    First of all I would strongly recommend that any such update is done at a time when this issue isn't likely to be a problem e.g. 3 AM
    Before running the update, ensure that the database is locked and, if anyone is logged in, they are given a few minutes to complete their work before the database is closed.

    Secondly I would question the need for repeatedly creating a new copy of the table as that can result in instability,
    Instead I recommend you empty the table using a delete query then add new records using an append query.

    I am aware that this doesn't answer the specific questions asked but that is because I believe them to be the wrong questions.

    Hope that helps, even if only indirectly.
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  3. #3
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    Sometimes an ounce of prevention is worth a pound of cure. It's generally accepted that repeatedly deleting and recreating a table is not a good approach. Better to just append and update. If you had to flush all from that table as part of the process, then it's not much better than recreating the table in terms of it being locked - except some also think that repeatedly recreating a table can promote db corruption.

    One thing you can do is try to create a locked recordset on the table with the dbDenyRead argument. If it errors, trap the error and present your custom message. Not sure if you should also specify dbDenyWrite as well. Wouldn't hurt I guess.
    Last edited by Micron; 03-18-2021 at 03:29 PM. Reason: clarification
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  4. #4
    cebrower is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2018
    Location
    Spring Lake, MI
    Posts
    110
    To clarify: this table contains inventory information that is displayed on the order entry form used by the salespeople as well as production projections based on current inventory and confirmed orders. For the data to be accurate the inventory table must be updated daily by deducting yesterday's shipped orders and adding yesterday's production. That data entry is accomplished first thing in the morning, and then the table is recreated. Yes, I could delete and append (and plan to make that change), but I still have the same issue with the table being in use somewhere. The inventory manager doesn't know if the table is open somewhere until the query fails. Then she has to figure out who has the table open. Often a user might have the table open and then walk away from their desk for hours at a time or that user's work station might be in a different building on the facility or working from home. I was hoping to be able to create code that would warn her that the table is open and maybe even inform her which user(s) have it open.

  5. #5
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    You have an answer for part A? As for part B, I know of no way to tell who has a lock on a table. You can look at the laccdb file to see what machine has opened the db file but unless you know who is on what pc that's not much help. Having a user table would help if it included a check field or time stamp field for being logged in. Then you can use a routine to get their Windows login name and machine id and associate either of those with their actual name in the user table.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  6. #6
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,977
    Hi again.
    This is a very common issue whenever table maintenance is required,. As such, it is normally solved by locking the database beforehand.
    I use a boolean Kickout field for the purpose whose value is set true when maintenance work is needed. A hidden form checks for the Kickout value every 30 seconds and if its True, a closedown sequence is started.
    The other issue of users leaving the app open when not in active use is normally solved using an inactivity timer. If the code detects that the user hasn't done any activity in a specified time e.g. 20 minutes, the app closes.

    I can understand why you would like to know if a table is in use and by whom but its not something I've ever seen done. Do bear in mind that the table could be in use by several people simultaneously on different workstations. Even if its possible, there are better solutions as outlined above
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  7. #7
    Minty is offline VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    Just as a slightly different tack on the problem at hand - If you had an inventory that was based on transactions in and out you wouldn't need to keep recreating this data, you could simply calculate it and it would be accurate at all times?
    I realise this isn't a 5 minute fix, but it is the only real way to manage a moving inventory.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

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

Similar Threads

  1. Check Table
    By jtmott in forum Programming
    Replies: 1
    Last Post: 06-06-2016, 08:29 AM
  2. How to check for sure that a table is a validation table?
    By magnusstefan in forum Database Design
    Replies: 23
    Last Post: 11-02-2015, 02:15 AM
  3. check table, if exist then update another table
    By JeroenMioch in forum Programming
    Replies: 6
    Last Post: 07-06-2012, 09:12 AM
  4. check a value on a table
    By udik in forum Programming
    Replies: 2
    Last Post: 12-05-2011, 03:57 AM
  5. how do i check against a table?
    By cheeese in forum Queries
    Replies: 1
    Last Post: 03-19-2011, 11:09 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