Solved

Record was already edited error.

Posted on 2008-10-10
6
181 Views
Last Modified: 2013-11-28
I have access frontend and SQL Sever backend
I have a form with tblDaily as part of the record source.
I add data to a field on frmMain, then click a button to go to a 2nd form.
In the button's code, I save frmMain (docmd.Save) before I open frm2nd.
I add data to frm2nd which also has tblDaily as part of the record source.
When I close frm2nd I requery and Save again using DoCmd.Save acForm, "frmMain"
and I'm back at frmMain.
When I type data into the frmMain I get the message...
    The data has been changed.
    Another user edited this record...
    Re-edit the record.
Why?  How many more saves do I need.
Does Docmd.save not work with SQL?

0
Comment
Question by:BobRosas
  • 4
  • 2
6 Comments
 
LVL 84
Comment Utility
No, DoCmd.Save won't work with SQL Server because DoCmd.Save has nothing to do with data. DoCmd.Save doesn't save your DATA, it saves any changes you've made to your FORM, and SQL Server has nothing to do with Form, Reports etc. Use this instead:

If Me.Dirty Then Me.Dirty = False

Note this will only work on the current object. If you need to save data on another form:

If Forms("YourFormName").Dirty Then Forms("YourFormName").Dirty = False



0
 

Author Comment

by:BobRosas
Comment Utility
Thank you so much for your response.
Would you explain more how this works?  
I think by setting the form to Me.Dirty I'm tricking it into thinking there are no previous changes so that I don't get the message.  If that's true, I'm not sure where to put the code.  I entered the code under 'On Activate" of the Main form so that when I go back to it from the second form I can enter more data but I'm still getting the same "data has been changed etc" message.
I really appreciate your help.
0
 
LVL 84

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 125 total points
Comment Utility
You're not setting the Form to Dirty, you're querying the form's Dirty property and, if True, then you're setting that Property to False, which forces Access to save your data.

Where you put this depends on where you need to force a save. Access typically saves when the record is "moved" (i.e you navigate to a different record, add a new record, etc) or when you explicitly call for a Save operation (via Code, menu selection, etc).

I'd do this BEFORE I moved off the first form ... IOW, in the Click event that opens your 2nd form, just before you open that form.
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:BobRosas
Comment Utility
Your explanation makes sense but I can't get it to work.
When I click on the button in form 1 to open form 2(frmDFT) I put in your code.  See attached.
I also added the code in the 2nd form on close for both forms.
I'm still getting the message on form one.

CODE WITHIN FIRST FORM

Private Sub cmdOpnDFT_Click()

    If IsNull(cboQCReportNo) Then

        MsgBox "You must enter a ReportNo and VersionNo to open this form."

        Exit Sub

    End If

    If Me.Dirty Then Me.Dirty = False

    DoCmd.OpenForm "frmDFT", acNormal

End Sub
 

CODE WITHIN 2ND FORM

Private Sub Form_Close()

    If Me.Dirty Then Me.Dirty = False

    If Forms("frmDaily").Dirty Then Forms("frmDaily").Dirty = False

End Sub

Open in new window

0
 

Author Comment

by:BobRosas
Comment Utility
There is a subform within the first main form that is auto filled.  Maybe that is the problem.  So I tried adding code to account for that but I've tried all the examples below and none of them will work.
Any thoughts?
Thanks again!

    If Forms("fsubDaily").Dirty Then Forms("fsubDaily").Dirty = False
    If Me.fsubDaily.Dirty Then Me.fsubDaily.Dirty = False
    If Forms!fsubDaily!Dirty Then Forms!fsubDaily.Dirty = False
    If Forms("Me!fsubDaily").Dirty Then Forms("Me!fsubDaily").Dirty = False
0
 

Author Closing Comment

by:BobRosas
Comment Utility
Thanks for your help.  I'll repost another question.
0

Featured Post

Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

Join & Write a Comment

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

762 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

9 Experts available now in Live!

Get 1:1 Help Now