Avatar of valmatic
valmatic
Flag for United States of America asked on

How to stop users from simultaneously updating a shared table

HI.  I have a shared access database that tracks returned goods and actions taken\pending.  I had some old email code that sent a separate email to each user where action was required.  This means a lot of email processing.  I am changing that to send out a single distinct email for action users and they can  now log into the database to view a report showing their specific actions.  To make this possible,  I turned all of the email alert code into a series update queries that  write to a table called RGAlerts.  I can run the refresh manually but I'd really like to refresh it each time the users either open or close the report, I'm not sure which would be best.  I have all of this working except for the report-driven table refresh.  I'm concerned about user updating simultaneously.  It would only hurt this one table that will get refreshed anyway but I think it could cause some confusion as that table could show duplicate entries if users happen to trigger the refresh at the same time..  
What is a good way to manage simultaneous updating in ACCESS 2010 and 2016?  Both clients are in place.  Is record locking possible to use in this situation?

thanks
DatabasesMicrosoft AccessVBA

Avatar of undefined
Last Comment
PatHartman

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Russ Suter

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Gustav Brock

First, apply a unique index to the table to avoid duplicate entries completely.
Then, adjust your code to handle the error if a duplicate entry should be attempted.

If records are edited simultaneously, first try if this is a real problem.
If it is, you can apply the simple method described in my article:

Handle concurrent update conflicts in Access silently
valmatic

ASKER
Thank you both for your responses.  I should have included my code with the post.  My code clears and rebuilds the table and if more than one person triggers the function call while the table refresh is already running then I get duplicate records.  This really isn't a record edit but a full table refresh, which takes about 5 seconds to complete.  It is likely that users will hit this thing at the same time so I think Pessimistic locking is best for this.  The function call is generated from a report request so I'll have to work in a warning to the users or make them aware they may need to retry the request again.  

Public Function RGAlerts()

    DoCmd.SetWarnings False
    DoCmd.RunSQL "DELETE * FROM RGAlerts"
    DoCmd.RunSQL "Insert into RGAlerts (RGAlertID) Values (0)"

    DoCmd.OpenQuery "AlertQry1_RGClosed_Initiator"
    DoCmd.OpenQuery "AlertQry2_CustRcptNoticeLate_Initiator"
    DoCmd.OpenQuery "AlertQry3_CustDispoNoticeLate_Initiator"
    DoCmd.OpenQuery "AlertQry4_LateEval_QI"
    DoCmd.OpenQuery "AlertQry4_LateEval_QM"
    DoCmd.OpenQuery "AlertQry4_LateEval_QIA"
    DoCmd.OpenQuery "AlertQry5_EvalsUnstartedDue1Day_QI"
    DoCmd.OpenQuery "AlertQry5_EvalsUnstartedDue1Day_QM"
    DoCmd.OpenQuery "AlertQry5_EvalsUnstartedDue1Day_QIA"
    DoCmd.OpenQuery "AlertQry6_RelFromHoldPendingEval_Initiator"
    DoCmd.OpenQuery "AlertQry6_RelFromHoldPendingEval_QI"
    DoCmd.OpenQuery "AlertQry6_RelFromHoldPendingEval_QM"
    DoCmd.OpenQuery "AlertQry6_RelFromHoldPendingEval_QIA"
    DoCmd.OpenQuery "AlertQry7_EvalCompleteCreditNotIssued_Initiator"
    DoCmd.OpenQuery "AlertQry7_EvalCompleteCreditNotIssued_AR"
    DoCmd.OpenQuery "AlertQry7_EvalCompleteCreditNotIssued_RSS"
    DoCmd.OpenQuery "AlertQry8_ItemsinPaintAfterPaintDueDate_2ndShiftSup"
    DoCmd.OpenQuery "AlertQry8_ItemsinPaintAfterPaintDueDate_BldgMgr"
    DoCmd.OpenQuery "AlertQry8_ItemsinPaintAfterPaintDueDate_PaintSup"
    DoCmd.OpenQuery "AlertQry8_ItemsinPaintAfterPaintDueDate_QI"
    DoCmd.OpenQuery "AlertQry9_ItemNotCompleteEvalCompletePlus5Days_QI"
    DoCmd.OpenQuery "AlertQry9_ItemNotCompleteEvalCompletePlus5Days_QM"
    DoCmd.OpenQuery "AlertQry9_ItemNotCompleteEvalCompletePlus5Days_QIA"
    DoCmd.OpenQuery "AlertQry10_ItemsOpen1WeekPostPartial_Initiator"
    DoCmd.OpenQuery "AlertQry10_ItemsOpen1WeekPostPartial_AR"
    DoCmd.OpenQuery "AlertQry11_ReceivedAwaitingEval_QI"
    DoCmd.OpenQuery "AlertQry11_ReceivedAwaitingEval_QM"
    DoCmd.OpenQuery "AlertQry11_ReceivedAwaitingEval_QIA"
    DoCmd.OpenQuery "AlertQry12_CustReceiptnotNotified_Initiator"
    DoCmd.OpenQuery "AlertQry13_RGsPending1Year_Initiator"
    DoCmd.OpenQuery "AlertQry13_RGsPending1Year_RSS"
    DoCmd.OpenQuery "AlertQry14_HoldPendingCust_Initiator"
    DoCmd.OpenQuery "AlertQry14_HoldPendingCust_QI"
    DoCmd.OpenQuery "AlertQry14_HoldPendingCust_QM"
    DoCmd.OpenQuery "AlertQry14_HoldPendingCust_RSS"
    
    DoCmd.RunSQL "Delete * from RGAlerts where RGAlertID = 0"
    DoCmd.SetWarnings True

End Function

Open in new window

PatHartman

I think your design probably still needs some work.  As you are experiencing, saving things that can be calculated leads to problems.  One thing to consider is that if specific people are assigned specific tasks, then update only that person's data.  And don't forget the unique index suggested by Gus.
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
valmatic

ASKER
I have a unique key but can't set a unique index on the column that would make a difference in this.  The record locking is a helpful tip.  That led me to a different way of doing this, maybe.  I'm closing this post.   thanks.
PatHartman

You can set a unique index on any combination of up to 10 columns IN ADDITION to the primary key.  You just have to use the indexes dialog to set it because you can't do it by setting the index property on the table because that only allows you to reference a single column at a time.

There is no reason to mess with record locking.  Leave that to the database engine.