Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Record was already edited error.

Posted on 2008-10-10
6
Medium Priority
?
199 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 85
ID: 22693236
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
ID: 22703233
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 85

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 500 total points
ID: 22703441
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:BobRosas
ID: 22704012
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
ID: 22705559
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
ID: 31505119
Thanks for your help.  I'll repost another question.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

824 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