Results 1 to 4 of 4

Thread: Dirty (XP/2K)

  1. #1
    5 Star Lounger
    Join Date
    Nov 2001
    Location
    Jerusalem, Israel
    Posts
    708
    Thanks
    0
    Thanked 1 Time in 1 Post

    Dirty (XP/2K)

    What is wrong with this bit of code?

    If Me.Dirty = True Then
    Debug.Print "2"
    End If

    It is on a command button that clears an unbound form, to check that you really want to clear the controls before you save them. (I did not yet write the message box). Why do i get the message:
    You have entered an expression that has an invalid reference to the property dirty

    Thanks

  2. #2
    Bronze Lounger
    Join Date
    Nov 2001
    Location
    Arlington, Virginia, USA
    Posts
    1,394
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Re: Dirty (XP/2K)

    You answered your own question - the form is unbound. The property reference is invalid for an unbound form. As noted in VBA help for Dirty Event: "This event applies only to bound forms, not an unbound form or report." Likewise the Dirty property only applies to bound forms.

    HTH

  3. #3
    5 Star Lounger
    Join Date
    Nov 2001
    Location
    Jerusalem, Israel
    Posts
    708
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Dirty (XP/2K)

    Thanks.
    Now, is there a way to do what I am trying to do- i.e. check if in an unbound form there is data, and check if the data entry person really wants to erase what is there?
    I assume I could loop through all the controls and see if they are not Null. Any better ideas?

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Dirty (XP/2K)

    Looping through the controls is probably a good way. The alternative would be to keep track of the "Dirty" state yourself:
    - Declare a variable IsDirty (Boolean) at the form module level.
    - In the After Update event of all controls that can be edited by the user, set IsDirty to True
    - Wherever needed, check if IsDirty = True.
    - After saving the data, or starting over (for instance by clearing all controls), reset IsDirty to False.

Posting Permissions

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