Results 1 to 9 of 9
  1. #1
    Join Date
    Jun 2006
    Posts
    11

    Unanswered: Dirty/AfterUpdate Problem

    Running into a little problem with the Dirty/AfterUpdate functions.

    What I'm trying to do is notify the user that there has been changes made in the form if they edited any data. Then I will ask the user if they would like to continue with the changes, or undo the changes.

    They way I have this setup is like the following....

    I declared a global boolean variable at the top of the forum like this:

    Private changeMade As Boolean

    Then under the form Dirty function I changed the variable to true, like this:

    Private Sub Form_Dirty(Cancel As Integer)

    changeMade = True

    End Sub


    Then under the form Close command, I did it like this (this is just the base of it):

    Private Sub cmdClose_Click()

    If changeMade = True Then
    MsgBox "changes were made"
    ElseIf changeMade = False Then
    MsgBox "changes weren't made"
    End If

    End Sub


    Now, this way seems to work just fine on about 3 out of 9 forms. I believe I know why this doesn't work on the rest of the forms. I think it might be becuase these forms are already Dirty once they are loaded. So it may not trigger the boolean flag. So what I did was try the AfterUpdate function in the same fashion, still no luck with that either.

    I'm just wondering if anyone has ever had the same problem with this, or maybe if anyone can give me some other type of input.

    Thanks.

  2. #2
    Join Date
    Jul 2004
    Location
    Blackburn, UK
    Posts
    169
    Well, if you are making changes to the form on open then your best option may be to make the form undirty once you have finished the code

    Form.Dirty = False

    Then you are with a clean sheet again and the code should trigger as normal
    Based on DAO 3.6 and Access 2000 + 2003
    VB.Net 2005 + ADO.Net

  3. #3
    Join Date
    Jun 2006
    Posts
    11
    Great idea, now, when you say make the form undirty somewhere in your code, where would you recommend doing that?

  4. #4
    Join Date
    Jul 2004
    Location
    Blackburn, UK
    Posts
    169
    Well you think that the other forms do not work because they are dirty from the beginning, well you must be running some code that is making the form dirty, if this is the case then make the form undirty at the end of this code excecution
    Based on DAO 3.6 and Access 2000 + 2003
    VB.Net 2005 + ADO.Net

  5. #5
    Join Date
    Jun 2006
    Posts
    11
    That's right, I'm taking a few fields from the main form, and transfering them over to the sub form. This is all happening on the sub form load. Like this:

    Private Sub Form_Load()

    Form_SubFormOne.SID = Form_Main.SID
    Form_SubFormOne.Customer = Form_Main.Customer

    Me.NavigationButtons = False

    End Sub


    So I should just be able to do this, right?

    Private Sub Form_Load()

    Form_SubFormOne.SID = Form_Main.SID
    Form_SubFormOne.Customer = Form_Main.Customer

    Me.NavigationButtons = False

    Me.Dirty = False

    End Sub

  6. #6
    Join Date
    Jul 2004
    Location
    Blackburn, UK
    Posts
    169
    If thats the final thing that is changing on the form then i would say yes.

    Perform all automatic modifications then make the form clean again, hope this works, ive neither tried no researched it, i just know the method exists and it sounds like the method you need to make everything fresh again.
    Based on DAO 3.6 and Access 2000 + 2003
    VB.Net 2005 + ADO.Net

  7. #7
    Join Date
    Jun 2006
    Posts
    11
    It still thinks it is dirty. Not sure what else would be changing on the form to think that way. I will keep trying different approaches to this.

  8. #8
    Join Date
    Jun 2006
    Posts
    11
    Ok, got rid of the global boolean variable, got rid of the dirty function (setting the boolean to true). Kept your idea in place (the Me.Dirty = False on form load), on the close command I just did something similar to this:

    If me.Dirty = true Then
    "Changes were made"
    ElseIf Me.Dirty = False Then
    "No changes were made"
    End If


    Now everything works GREAT. Thanks alot for the help, much appreciated.

  9. #9
    Join Date
    Jul 2004
    Location
    Blackburn, UK
    Posts
    169
    No probs, glad it helped
    Based on DAO 3.6 and Access 2000 + 2003
    VB.Net 2005 + ADO.Net

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •