Write conflict - save record (1 Viewer)

Danick

Registered User.
Local time
Today, 03:31
Joined
Sep 23, 2008
Messages
351
I have a continuous form where when a user double clicks on the subject, another (single) form opens to be able to edit that particular record. The continuous form is still left open in the background.

But since the user can also change the words in the subject line while in the continuous form, a write conflict error occurs if the user also changes that record after it is opened in the single form. I was going to use the DoCmd.RunCommand acCmdSaveRecord but then found that using me.dirty just before opening the other form works even better.
Code:
If me.dirty then
me.dirty = false
end if

Although this is working fine, I just don't like using something I found on the internet without understanding how it works. Would appreciate if anyone has a simple explanation as how this code is able to save a record without any actual save record VBA. Thanks.
 

June7

AWF VIP
Local time
Yesterday, 23:31
Joined
Mar 9, 2014
Messages
5,466
Setting the form dirty property to false forces the form to commit edits to table so the false condition will be the true state. I know - mind blowing!
 

MarkK

bit cruncher
Local time
Today, 00:31
Joined
Mar 17, 2004
Messages
8,179
You'll get a write conflict if you have a pending edit on the same row in two different recordsets. Setting Dirty = False in a form resolves any pending edit in that form, saving any changes to disk. Then, when you open your other form showing only the single row, it becomes the only recordset with a pending edit on that row. This resolves your write conflict, so this is a good practice.

Also, you don't need the If...End If block. Just do...
Code:
   Me.Dirty = False
If it was false before that, nothing happens, so testing it with the If Me.Dirty doesn't save you anything.

Another tip, if you open a popup form to allow edits to a single row, open the form with the acDialog switch in DoCmd.OpenForm, like...
Code:
    DoCmd.OpenForm "fEditWIZ", , , , , acDialog
...so the form is modal and popup, and the user MUST deal with it, or close it, in order to proceed. This will alleviate any other write conflicts that might occur if your row-specific edit wizard is still open.

hth
Mark
 

Danick

Registered User.
Local time
Today, 03:31
Joined
Sep 23, 2008
Messages
351
Also, you don't need the If...End If block. Just do...
Code:
   Me.Dirty = False
If it was false before that, nothing happens, so testing it with the If Me.Dirty doesn't save you anything.

WOW - if the previous If...End If block was a Jedi Mind Trick, this one is even more mind blowing. :confused: Thanks for that.

Another tip, if you open a popup form to allow edits to a single row, open the form with the acDialog switch in DoCmd.OpenForm, like...
Code:
    DoCmd.OpenForm "fEditWIZ", , , , , acDialog
...so the form is modal and popup, and the user MUST deal with it, or close it, in order to proceed. This will alleviate any other write conflicts that might occur if your row-specific edit wizard is still open.

As for the other tip to make the single form a popup. I was using the acDialog switch for new records, but unfortunately after some changes to the single form and adding more double click events on the singe form, I decided to just use a button on the continuous form that closes the continous form before creating a new record with the single form. So I think I'll just leave that one as is since it's working fine. And you know what they say, it it isn't broken,...

Thanks again for the explanation.
 

Users who are viewing this thread

Top Bottom