How to avoid Write Conflict when updating records with CurrentDb.Execute?

With the following code, I keep getting a dialog box that pops up with Write Conflict once I do a Select All as I click on its check box.  The highlight ends up on CurrentDB.Execute sSQL and then I get the dialog box.

This record has been changed by another user since you started editing it.  If you save the record, you will overwrite the changes the other user made.

The only problem there is no other user just me running VBA Code after an event - I understand that I have both the check box after update and click events running the same code but it doesn't seem to refresh the records correctly?

How may I adjust the following to not have that dialog box and process the transactions smoothly?  Is there a better method than what I'm doing instead of using both the click event and after update to get the check boxes refresh properly on the form?
Private Sub chkShow_AfterUpdate()
  Call Adj_Form
End Sub

Private Sub chkShow_Click()
  Call Adj_Form
End Sub

Private Sub Adj_Form()

  Dim sSQL As String
  
  If chkShow.Value = True Then chkShow.Value = False Else chkShow.Value = True
  
  If [Dept_Name] = "( Select All ) -------------------------" Then
    sSQL = "UPDATE [shwPROJ_DPT] SET [Show] = " & chkShow.Value
    CurrentDb.Execute sSQL
    DoEvents
  End If
  
  Call Adj_Show_All
  
End Sub

Open in new window

TowerIII.mdb
LVL 1
stephenlecomptejrAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

lee555J5Commented:
Delete the AfterUpdate event. You do not need both.
Add the line
Screen.ActiveForm.Refresh
after the "If chkShow.Value = True Then..." line. This saves any changes to the record by the If statement.
Lee


Rey Obrero (Capricorn1)Commented:
see if this is what you want
TowerIII.mdb
stephenlecomptejrAuthor Commented:
lee555J5:

This is the coding that I have per your instructions but it still doesn't work -

capricorn1:

Your version of my demo works but I can compare my code in the VBA window with yours - line by line and I don't see a difference?  How come yours works with the same VBA code?
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

stephenlecomptejrAuthor Commented:
Sorry lee - didn't post the coding.
Private Sub chkShow_Click()
  Call Adj_Form
End Sub

Private Sub Dept_Name_Click()
  Call Adj_Form
End Sub

Private Sub Adj_Form()

  Dim sSQL As String
  
  If chkShow.Value = True Then chkShow.Value = False Else chkShow.Value = True
  Screen.ActiveForm.Refresh
  If [Dept_Name] = "( Select All ) -------------------------" Then
    sSQL = "UPDATE [shwPROJ_DPT] SET [Show] = " & chkShow.Value
    CurrentDb.Execute sSQL
    Me.Refresh
  End If
  
  
End Sub

Open in new window

Rey Obrero (Capricorn1)Commented:
here is the code, i added a where clause
Private Sub Adj_Form()

  Dim sSQL As String
  
  If chkShow.Value = True Then chkShow.Value = False Else chkShow.Value = True
  
  If [Dept_Name] = "( Select All ) -------------------------" Then
    sSQL = "UPDATE [shwPROJ_DPT] SET [Show] = " & chkShow.Value & " where Dept_Code<> 'n/a'"
    CurrentDb.Execute sSQL
    Me.Refresh
  End If
  
  
End Sub

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
stephenlecomptejrAuthor Commented:
capricorn1 is an inspirational genius!

=)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.