Solved Save data from a different form. Write Conflict Error (1 Viewer)

jsdba

Registered User.
Local time
Today, 05:48
Joined
Jun 25, 2014
Messages
165
Hi Experts,

I'm in need some help. I have 2 forms. Main form bound, pop-up form unbound. I need to be able to change and save data on the main form using the pop-up form.

Using a refresh command to the main form will eliminate the write conflict error but causes a different error because my the refresh command triggers some other code so i cant use that.

Here's what happening...
  1. Pop up form makes changes to record on main form using a submit button
  2. if code fails for any reason go to error handler
  3. error handler undos/reverse the changes made to the data via
    Code:
    Forms!MainForm!field = ""
  4. write conflict error occurs
Is there a way to save the record after step 3 on the main form without using refresh
Code:
Forms!Mainform!Form.refresh
. I've also tried
Code:
Forms!MainForm.Dirty = False
to no avail.

any help is appreciated
 

theDBguy

I’m here to help
Staff member
Local time
Today, 02:48
Joined
Oct 29, 2018
Messages
21,357
Hi. What is the exact code you're using to update the main form from the popup form?
 

jsdba

Registered User.
Local time
Today, 05:48
Joined
Jun 25, 2014
Messages
165
Hi. What is the exact code you're using to update the main form from the popup form?

forms!frmMainForm!Field1 = me.Field1 (pop-up form)
forms!frmMainForm!Field2 = me.Field2 (pop-up form)
 

theDBguy

I’m here to help
Staff member
Local time
Today, 02:48
Joined
Oct 29, 2018
Messages
21,357
forms!frmMainForm!Field1 = me.Field1 (pop-up form)
forms!frmMainForm!Field2 = me.Field2 (pop-up form)
Hi. Thanks for the additional information. That by itself shouldn't cause a write conflict. I wonder if there are other things going on with your main form. Are you able to share a demo copy of it? You could probably take out the data, or replace it with some test data.
 

jsdba

Registered User.
Local time
Today, 05:48
Joined
Jun 25, 2014
Messages
165
Hi. Thanks for the additional information. That by itself shouldn't cause a write conflict. I wonder if there are other things going on with your main form. Are you able to share a demo copy of it? You could probably take out the data, or replace it with some test data.
Sorry i cant. let me try and shed some more insight. the write conflict only happens with when the error handler triggers. so the data is updated bu the user submit button, then gets updated again by the error handler. does that help?
 

theDBguy

I’m here to help
Staff member
Local time
Today, 02:48
Joined
Oct 29, 2018
Messages
21,357
Sorry i cant. let me try and shed some more insight. the write conflict only happens with when the error handler triggers. so the data is updated bu the user submit button, then gets updated again by the error handler. does that help?
Is the error handler in the main form or the popup form?
 

jsdba

Registered User.
Local time
Today, 05:48
Joined
Jun 25, 2014
Messages
165
Interesting. Is your code automatically trying to save the changes to the table right away?
i'm trying to force a save before the error handler triggers. a refresh would do the trick but the refresh cause other code to run which i don't want. i'm trying to force a save on the main form without using refresh.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 02:48
Joined
Oct 29, 2018
Messages
21,357
i'm trying to force a save before the error handler triggers. a refresh would do the trick but the refresh cause other code to run which i don't want. i'm trying to force a save on the main form without using refresh.
Okay, that might not be the right way to go. If the main form is in locked mode due to a prior edit, then editing it from another process and then trying to save it might be causing the write conflict (or something like that). It would be really nice to examine your file first hand to isolate the problem. Aren't you able to create a demo version with only the problem objects included?
 

jsdba

Registered User.
Local time
Today, 05:48
Joined
Jun 25, 2014
Messages
165
Okay, that might not be the right way to go. If the main form is in locked mode due to a prior edit, then editing it from another process and then trying to save it might be causing the write conflict (or something like that). It would be really nice to examine your file first hand to isolate the problem. Aren't you able to create a demo version with only the problem objects included?
I didnt realized i had some sql code updating the same record. i feel stupid. just had to change the sql to MainForm!Field=PopupForm!Field. thank you though. solved
 

theDBguy

I’m here to help
Staff member
Local time
Today, 02:48
Joined
Oct 29, 2018
Messages
21,357
I didnt realized i had some sql code updating the same record. i feel stupid. just had to change the sql to MainForm!Field=PopupForm!Field. thank you though. solved
Hi. Glad to hear you got it sorted out. Good luck with your project.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 05:48
Joined
Feb 19, 2002
Messages
42,970
Just FYI, always save the current form if it is dirty before you open another form or report.

NEVER use Me.Refresh or Me.Requery to save the current record. Both actions are intended for other purposes and only save the record before performing their assigned function as a side effect. ALWAYS use either
Code:
If Me.Dirty = True Then
    DoCmd.RunCommand acCmdSaveRecord
End If



Or



If Me.Dirty = True Then
    Me.Dirty = False
End If
 

Users who are viewing this thread

Top Bottom