Solved

Write concflict in MS Access

Posted on 2013-05-15
10
247 Views
Last Modified: 2013-12-20
I have a form in MS Access with  subform that has radio buttons and textboxes. When I try to modify the subform by changing the radio button or entering text into the textbox, it is displaying the "write conflict" error at the following line in one of the functions.

If Me.Dirty Then
    DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
 End If

Frankly, I have no idea about how it is validating. Please let me know what other details I need to provide.
0
Comment
Question by:Angel02
  • 5
  • 4
10 Comments
 
LVL 61

Expert Comment

by:mbizup
ID: 39168845
Try adding the following code to the  subform control's Enter event

Docmd.runcommand  acCmdSaveRecord
0
 
LVL 19

Expert Comment

by:Eric Sherman
ID: 39168938
Usually that means you have some other event or code that started changing the record as well.  You will need to evaluated all code you have attached to the form.

ET
0
 

Author Comment

by:Angel02
ID: 39169335
@mbizup
I added it but it did not change anything.

I first click on a "edit" button which loads the records (rows) that are to be edited. The fields values of the rows are populated into textboxes and radiobuttons.  Below is the function that does that:

Private Sub cmdEditRt_Click()
Dim strSource As String
'Steps
'1.Check if not exist
Dim rte As Integer
Dim Dt As Date
Dim flgOK As Boolean
   strSource = "SELECT tbl1.* FROM tbl1 " _
    & " WHERE (((Rt)=" & 0 & "))" _
    & " AND location= " & Location & ";"

Me.RecordSource = strSource

If Me.txtRt <> "" And Me.txtDate <> "" Then
    rte = txtRt
    Dt = txtDate
'Check if valid RT
     Select Case RtStatus(rte, Dt)
     
      Case 0
            MsgBox "not found!", , "Validation error"
      Case 1, 2
            flgOK = True
      Case 3
             MsgBox "started!", , "Validation error"
     Case Else
            If AppMode <> 4 Then
                MsgBox "already processed !", , "Validation error"
            Else 'just for diadnostic
                flgOK = True
            End If
     End Select
     If flgOK Then
         strSource = "SELECT tbl1.* FROM tbl1 " _
        & " WHERE ((Rt_Number)=" & rte _
        & " AND (finish_date)=#" & Format(Dt, "yyyy-mm-dd") & "#)" _
        & " AND location= " & Location & ";"

                Me.RecordSource = strSource
       End If
 
 Else ' rt is missing
        MsgBox "Please provide rt #!", , "Validation error"
 End If


End Sub

'********************

I then try to modify the textbox to update the row in the table. It is when I get the write conflict. The function that is called when I try to edit is below:
Public Sub ChangePayment()
If Me.fraPaymentType.Value = 0 Then
    Me.AmtTender_pay_cash = ""
    Me.AmtTender_pay_cash.SetFocus
    Me.AmtTender_pay_check = ""
    Me.AmtTender_pay_credit = ""
   
ElseIf Me.fraPaymentType.Value = 1 Then
    Me.AmtTender_pay_cash = ""
     Me.AmtTender_pay_check = ""
    Me.AmtTender_pay_credit = Me.SubTotal_forStop
ElseIf Me.fraPaymentType.Value = 2 Then
    Me.AmtTender_pay_cash = Null
    Me.AmtTender_pay_check = Me.SubTotal_forStop
    Me.AmtTender_pay_credit = ""
End If
If Me.Dirty Then
    DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70 'FAILS HERE End If

End Sub

Is the cmdEditRt_Click function loacking the record? How do I check and if so what do I do to avoid?
0
 
LVL 61

Accepted Solution

by:
mbizup earned 500 total points
ID: 39170260
I believe you are getting that error because Access sees your manual edits and your code edits as two separate 'people' editing the record at the same time.

The key to resolving this type of error is to save the record between different types of edits.  The code I suggested earlier will force-save a record (so will me.Refresh as shown below), but try placing it immediately before your edit code instead.  This is assuming that the textbox you are editing is located on the same form (or subform) as your code.

Public Sub ChangePayment()

Me.refresh

If Me.fraPaymentType.Value = 0 Then
    Me.AmtTender_pay_cash = ""
    Me.AmtTender_pay_cash.SetFocus
    Me.AmtTender_pay_check = ""
    Me.AmtTender_pay_credit = ""
    
ElseIf Me.fraPaymentType.Value = 1 Then
    Me.AmtTender_pay_cash = ""
     Me.AmtTender_pay_check = ""
    Me.AmtTender_pay_credit = Me.SubTotal_forStop
ElseIf Me.fraPaymentType.Value = 2 Then
    Me.AmtTender_pay_cash = Null
    Me.AmtTender_pay_check = Me.SubTotal_forStop
    Me.AmtTender_pay_credit = ""
End If

docmd.runcommand accmdsaverecord

End Sub

Open in new window

0
 

Author Comment

by:Angel02
ID: 39175870
I placed Me.refresh immediately before the edit code as you mentioned. The runtime error now occurs at Me.Refresh in ChangePayment(). So this means it has to be saved even before getting to this function? I have Docmd.runcommand  acCmdSaveRecord at  subform Enter() like you suggested. So the record is being accessed somewhere in between?
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 

Author Comment

by:Angel02
ID: 39181204
I wanted to add that this application used to work perfectly last week. I changed the connection string and it started throwing the error. I then changed the connection string back to the older one but it still would throw the write conflict.
What could be the cause?
0
 
LVL 61

Expert Comment

by:mbizup
ID: 39181222
Is your data stored in Access, SQL Server, or something else?
0
 

Author Comment

by:Angel02
ID: 39181444
Data is stored in MySQL.
It is accessed via Access.
0
 
LVL 61

Assisted Solution

by:mbizup
mbizup earned 500 total points
ID: 39181593
Try this -

For any bit fields in the table related to the form(s) where you are having this issue:

1.  Ensure that NULLS are not allowed
2.  Ensure that any existing nulls are updated with FALSE.
0
 

Author Comment

by:Angel02
ID: 39181626
I checked all the four tables related to the form and apparently none of them have even one bit field.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now