We help IT Professionals succeed at work.

How to stop users from simultaneously updating a shared table

valmatic
valmatic asked
on
112 Views
Last Modified: 2018-10-13
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
Comment
Watch Question

Senior Software Developer
CERTIFIED EXPERT
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION
CERTIFIED EXPERT
Most Valuable Expert 2015
Distinguished Expert 2018

Commented:
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

Author

Commented:
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

CERTIFIED EXPERT
Distinguished Expert 2017

Commented:
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.

Author

Commented:
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.
CERTIFIED EXPERT
Distinguished Expert 2017

Commented:
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.

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions