The data has been changed

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • reginaldmerritt
    New Member
    • Nov 2006
    • 201

    The data has been changed

    This seems to be a common issue, I've read all the solutions to this I could find and I can't see where I'm still going wrong.

    I have two forms, one is a continuous list of records the other is a single record showing further details.

    From the single record form I save the record, then run a public subroutine which loops though all of the records and updates them, I then run a requery on both forms.

    Code:
    Private Sub ExamVenueID_AfterUpdate()
    
    If Me.Dirty Then Me.Dirty = False
    
    UpdateExamVenueHireStatus
    Me.ExamVenueHireStatusID.Requery
    Forms.FRMExamVenueHire.Requery
    
    End Sub
    I won't put up the content of the public subroutine which uses record sets to update all the records just yet; as this subroutine is a little complex.

    The first time I run through ExamVenueID_Aft erUpdate above, everything works fine, the second time I get the "The data has been changed" error.

    I have saved the record, I don't understand what else I should do, any suggestions ?
  • twinnyfo
    Recognized Expert Moderator Specialist
    • Nov 2011
    • 3662

    #2
    Reginald,

    Have you tried stepping through each line of code as it executes on the form? Also, do you have anything running on the OnCurrent Event of either form? If there are any changes that occur in this event, it may be changing some of your data.

    I have had a few issues similar to your in the past, and it simply took going line by line to see what values are changing and when they are changing.

    This may not offer a "solution" but offers a method of troubleshooting . There may also be some bigger brains on this forum who could ID the problem right away, but without the DB in hand (or the code) it's difficult to pinpoint such an error.

    Comment

    • reginaldmerritt
      New Member
      • Nov 2006
      • 201

      #3
      Fair enough twinnyfo, thank you for your post.

      I don't have anything running OnCurrent but when i use a line toggle break on the 'if me.dirty then me.dirty = false' the error appears before it gets to that point. In other words the ExamVenueID_Aft erUpdate event doesn't even get to happen, therefore i have been unable to go though each line as Access kicks me out before its even begun.

      Comment

      • TheSmileyCoder
        Recognized Expert Moderator Top Contributor
        • Dec 2009
        • 2322

        #4
        Then you need to first determine which event causes the error to fire.

        You say it works the first time (without error) but gives an error the second time around. My guess would be that your UpdateExamVenue HireStatus causes the active record to be changed as well.

        Try adding a Me.Refresh to the end of the code shown in your first post, and lets us know if that solves anything.

        Comment

        • reginaldmerritt
          New Member
          • Nov 2006
          • 201

          #5
          Hi Smileycode, thanks for your post. Yes your right the problem is with changing an active record but I thought by using "me.dirty" and ".refresh" that I would have covered everything.

          I was trying to refresh just the field that was changed "Me.ExamVenueHi reStatusID.Requ ery" via the record set used in UpdateExamVenue HireStatus, I tried "me.refresh " instead but that didn't help, but I see where your coming from.

          UpdateExamVenue HireStatus was on a separate module from any form, not because it had to be, just because I thought maybe in the future I might need to run it from another form. It also used a recordset to loop though all the records, but again this wasn't really necessary. Trying to be to cleaver I think.

          I moved UpdateExamVenue HireStatus back into the forms code and rather than using a record set to loop though all the records it now just use "me." to change the record being viewed.

          This has now gotten rid of the 'The data has been changed' error.Bit of of a cop out I know, and I'm sure I'll come across this problem again in the future so perhaps I'll revisit this some time.

          Comment

          • zmbd
            Recognized Expert Moderator Expert
            • Mar 2012
            • 5501

            #6
            Try the Me.Requery as it appears that the underlying query has changed. The dirty=false saved the record; however it doesn't always make that known... weird little quirk in access especially with split databases.

            I've ran into something very similar.
            When the database was all in one... the code worked just fine; however, once split I ran into just that message...
            I initially tried the "refresh" thingy - no joy.
            I then ran across this:http://allenbrowne.com/bug-01.html when led me to http://office.microsoft.com/en-us/ac...005187598.aspx so I then changed to a full requery within the forms code and all was well.

            -z
            Last edited by zmbd; Aug 17 '12, 02:53 PM.

            Comment

            • TheSmileyCoder
              Recognized Expert Moderator Top Contributor
              • Dec 2009
              • 2322

              #7
              Glad to hear you got it working. Whether or not the code is within the module should not in itself affect the result. However opening a secondary recordset (the primary being the recordset bound to the form) this behaviour would certainly occur. Now I don't know exactly what you are doing, but in general I would never try to do anything with a recordset that could be done by simply using the Me.???, so from what you have described I would not call it a cop-out.

              Ps. Of course you cannot use Me from a seperate module, but its perfectly possible to pass the current form to a seperate procedure in a module.

              Comment

              Working...