Why is this form dirty? (1 Viewer)

mjdemaris

Working on it...
Local time
Today, 14:31
Joined
Jul 9, 2015
Messages
424
Riddle me this:

I open a bound form, single table query, with ONE label whose caption is set on load event. The form is opened via a click event on a datasheet, filtered to the ID of the clicked record.

The first text box gets the focus, also on load event.

Without changing anything at all: Dirty on Load: false; dirty on before update: true.

close button: close form, set not to save.

I have a message box that pops up to confirm changes and it fires every time I close the form.

Edit: I forgot to mention that the dirty event does not fire.
The form calling code:
Code:
DoCmd.OpenForm "GEN_F_L1_SupplierDetail", acNormal, , "[ID] = " & Me.txtID, acFormReadOnly, acWindowNormal

Before update:
Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
   
    Debug.Print "Dirty Before Update: " & Me.Dirty
   
    If Me.Dirty Then
        If MsgBox("Confirm Changes?", vbQuestion + vbOKCancel, "Data Has Changed.") = vbCancel Then
            Me.Undo
        Else
       
        End If
   
    End If
End Sub

From the Immediate window:
Dirty Load: False
Dirty Before Update: True
Dirty Close: False

Thoughts on how I could track this down?

thanks,
mike
 
Last edited:

theDBguy

I’m here to help
Staff member
Local time
Today, 14:31
Joined
Oct 29, 2018
Messages
21,358
Hmm, maybe add a procedure in the Form's Dirty event to help track it down?
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 16:31
Joined
Feb 28, 2001
Messages
27,001
OK, I doubt this will do it, but as a test, don't change that label caption.

But... is there a chance that there is an autonumber involved here?

OR is there a default value on any field?
 

mjdemaris

Working on it...
Local time
Today, 14:31
Joined
Jul 9, 2015
Messages
424
the DB is split, link to the three tables in the BE.
There are two default value fields, however, defaults should only populate on a new record upon data entry, no?

Also, I just realized one default value is probably not valid, for the payment method combo box.

One last thing:
I finished building a second form, almost identical to the first, and without the "dirty" problem.

The main form is: GEN_F_L1_Supplier Search.
The one in question is the Supplier Detail and the non-dirty form is Supplier Detail2. (Spaces added to form names for better readability.)
 

Attachments

  • vendors.zip
    851.3 KB · Views: 226

Pat Hartman

Super Moderator
Staff member
Local time
Today, 17:31
Joined
Feb 19, 2002
Messages
42,976
Just FYI, the BeforeUpdate event fires ONLY if the form is dirty so you do not need to check for dirty inside that event. The answer will always be true.

The form isn't being dirtied by magic. There is some code, somewhere that is dirtying it. Try posting the entire class module of the form. Also, you should post the code in the procedure that opens the form. Perhaps there is code there that is dirtying the form.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 14:31
Joined
Oct 29, 2018
Messages
21,358
the DB is split, link to the three tables in the BE.
There are two default value fields, however, defaults should only populate on a new record upon data entry, no?

Also, I just realized one default value is probably not valid, for the payment method combo box.

One last thing:
I finished building a second form, almost identical to the first, and without the "dirty" problem.

The main form is: GEN_F_L1_Supplier Search.
The one in question is the Supplier Detail and the non-dirty form is Supplier Detail2. (Spaces added to form names for better readability.)
Hi. Thanks for posting a sample db. You may have to give us a step-by-step instructions on how to duplicate the error. I opened the main form and clicked on the first record, which opened the other form, but the Immediate Window stayed empty even after I clicked on the Close button. This was after I linked the tables and added one record, so the form would open without an error.
 

mjdemaris

Working on it...
Local time
Today, 14:31
Joined
Jul 9, 2015
Messages
424
Hi. Thanks for posting a sample db. You may have to give us a step-by-step instructions on how to duplicate the error. I opened the main form and clicked on the first record, which opened the other form, but the Immediate Window stayed empty even after I clicked on the Close button. This was after I linked the tables and added one record, so the form would open without an error.
Right, you will probably need to change the code to open the GEN_F_L1_SupplierDetail form, rather than #2 form. My apologies for not changing it ahead of time.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 14:31
Joined
Oct 29, 2018
Messages
21,358
Right, you will probably need to change the code to open the GEN_F_L1_SupplierDetail form, rather than #2 form. My apologies for not changing it ahead of time.
Hi. Thanks for the additional information. I think I found the cause of your problem. When you click on the record, the detail form opens. At this point, the focus is on the Company Name. If you don't do anything and simply close the form or click on the Close button, the form gets dirtied. The reason for this is because you have code in the Exit event of the Company Name textbox that updates that data/record to proper case. If you comment that code out, you won't have this problem. Obviously, that won't be the fix. You will have to decide how to handle it properly. My suggestion is to use the AfterUpdate event of the Textbox, instead of the Exit event.
 
Last edited:

Pat Hartman

Super Moderator
Staff member
Local time
Today, 17:31
Joined
Feb 19, 2002
Messages
42,976
Probably better to use the BeforeUpdate event of the form. That way, the code won't run unless the user dirties the form.
 

mjdemaris

Working on it...
Local time
Today, 14:31
Joined
Jul 9, 2015
Messages
424
@Pat Hartman so, the form is not really dirty, then, after commenting out the proper case code on the exit event of the text box, as @theDBguy mentioned.

Even without changing anything, the before update event fires. So, something is causing it to still think it's dirty.

I've worked around this by moving the confirm changes message box and not using the before update event.

But I do have the second form which has the same code in the before update event as you saw in the sample DB, but that event does not fire...

So, still a mystery, but it works.

Edit: I'll be using the second form from now on.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 14:31
Joined
Oct 29, 2018
Messages
21,358
@Pat Hartman so, the form is not really dirty, then, after commenting out the proper case code on the exit event of the text box, as @theDBguy mentioned.

Even without changing anything, the before update event fires. So, something is causing it to still think it's dirty.

I've worked around this by moving the confirm changes message box and not using the before update event.

But I do have the second form which has the same code in the before update event as you saw in the sample DB, but that event does not fire...

So, still a mystery, but it works.

Edit: I'll be using the second form from now on.
Hmm, it doesn't seem to be a mystery to me anymore. All I had to do was comment out the ProperCase code in the Exit event of Company Name. The two forms don't have the same code. The one that works (Details2) doesn't have the Exit event code, does it?
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 17:31
Joined
Feb 19, 2002
Messages
42,976
I was talking about what theDBguy found. Move THAT code to the BeforeUpdate event since THAT code is making the form dirty. That way, it won't run unless the user has already dirtied the form himself.
 

mjdemaris

Working on it...
Local time
Today, 14:31
Joined
Jul 9, 2015
Messages
424
I opened up the sample DB and commented out the ProperCase code and it still says it's dirty. I am not sure how it works for you if that's all you commented out.

And by Dirty, I mean that if I debug.print dirty in the Before Update event, it says dirty is true. I guess the question becomes: Why does it think Dirty=true in the Before Update event, but no where else?
 

theDBguy

I’m here to help
Staff member
Local time
Today, 14:31
Joined
Oct 29, 2018
Messages
21,358
I opened up the sample DB and commented out the ProperCase code and it still says it's dirty. I am not sure how it works for you if that's all you commented out.

And by Dirty, I mean that if I debug.print dirty in the Before Update event, it says dirty is true. I guess the question becomes: Why does it think Dirty=true in the Before Update event, but no where else?
Okay, just to make sure we're on the same page, I redownloaded your file from post #6 and only did the following changes.
  1. Imported all the BE tables (rather than link them)
  2. Modified the Search Form click event to open the Details Form, instead of the Details2 Form
  3. Commented out the ProperCase code in the Exit Event of the Company Name Textbox
Can you please give it a try and let us know if you still see the problem you were having? Again, all I'm asking you to do is open the Search Form, Click on the Company Name to open the Details Form and then Click on the Close button on the Details Form. I don't expect you to get the Dirty/Confirmation message.

If you do any steps other than the ones I mentioned above and get the warning message, please let us know what steps you added.

Thanks.
 

Attachments

  • VEN_fe.zip
    227.2 KB · Views: 206

Users who are viewing this thread

Top Bottom