Form_Dirty will not fire

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bigukfan
    New Member
    • Mar 2010
    • 21

    Form_Dirty will not fire

    Hi, need some help - Using Access 2003, Windows XP
    Trying to get the Form Dirty event to work, but no joy. I was under the impression when a key is pressed in a control such as a TextBox or a selection from a ComboBox is made, the Form's Dirty event fires. Here is my code
    Code:
    Private Sub Form_Dirty(Cancel As Integer)
    If Me.Dirty Then Me!cmdTest.Enabled = True
    End Sub
    Why is this not working?
  • Stewart Ross
    Recognized Expert Moderator Specialist
    • Feb 2008
    • 2545

    #2
    This event only applies to a bound form - are you using an unbound form by any chance (one that has no underlying recordsource table or query)?

    Otherwise, assuming that you are physically typing into a bound field or selecting a combo value for a bound field, there is no obvious problem unless another event is being fired before the Dirty event and you are handling that in a way which cancels the current record. Here is what the MS-Help says about the event sequence:

    Originally posted by MS Help
    Changing the data in a record by using the keyboard causes keyboard events to occur in addition to control events like the Dirty event. For example, if you move to a new record and type an ANSI character in a text box in the record, the following events occur in this order:

    KeyDown > KeyPress > BeforeInsert > Dirty > KeyUp

    The BeforeUpdate and AfterUpdate events for a record occur after you have entered the new or changed data in the record and moved to another record (or clicked Save Record on the Records menu), and therefore after the Dirty event for the record.
    -Stewart

    Comment

    • bigukfan
      New Member
      • Mar 2010
      • 21

      #3
      Hi Stewart, Yes, I should have said my Form is unbound. I take it from your answer there is no way to get Dirty to work with an unbound Form? If that is the case I'll just have to put code in every control event, what a pain!

      Comment

      • Stewart Ross
        Recognized Expert Moderator Specialist
        • Feb 2008
        • 2545

        #4
        Hi bigukfan, it is indeed the case that the event works with bound forms only, as mentioned in the MS-Help entry:

        Originally posted by MS Help
        This event applies only to bound forms, not an unbound form or report
        All you need to do, though, is to write a single update routine and place a call to it in the AfterUpdate event of each control that you want to respond to. I know that it is not the same as using On Dirty, but it's the best way forward when there is no other alternative...

        -Stewart

        Comment

        • jbrumbau
          New Member
          • Sep 2007
          • 52

          #5
          I had the same problem with a form of mine. I found out though that when I removed a Form_BeforeInse rt event I made, Form_Dirty started working fine again.

          Comment

          Working...