me.dirty problem (1 Viewer)

ryetee

Registered User.
Local time
Today, 02:36
Joined
Jul 30, 2013
Messages
952
I have just completed some very small enhancements to a small system. This was with access 2016. I have deployed the software to 2 machines. 1 is using either 2010 or 2016 access the other is , I think 2007.
On the 2007 machine he is getting an error to a form that has not changed and worked before. A lot of forms have the "small door icon" to exit. The code on every (or at least most) of these forms is this
On Error GoTo Err_Command7A_Click


If Me.Dirty Then Me.Dirty = False
DoCmd.Close

Exit_Command7A_Click:
Exit Sub

Err_Command7A_Click:
MsgBox Err.Description
Resume Exit_Command7A_Click

I am effectively getting error 2455 with the message along the lines of
"you have specified an expression that contains an invalid reference to the dirty property."

On the forms where he is getting this error they are not bound to any record source. Having googled this to death it says that the me.dirty command won't work on unbound forms.

Okay this is fair enough and at first look an easy problem to overcome but the questions are why has this worked for the past 3/4 years and used on a daily basis for the 2007 machine, why does it still work for 2010/2016 and why has it suddenly stopped working for 2007.

AND as part of the deploy we copy the front end and database to a different folder on the clients machine and then relink tables. The older versions of the program still work. One of the things that WAS changed on one of the forms was getting rid of the ability to close the form using the small "x" in top right hand corner, but that wasn't done to all the forms that are now failing. Anybody got any ideas so I don't have to changed every single form that there is a problem with?
 

Minty

AWF VIP
Local time
Today, 02:36
Joined
Jul 26, 2013
Messages
10,355
That's weird.

There have been some odd bugs recently with MS updates causing issues? Maybe worth looking at the windows update history and "rolling back" the updates to see if the issue disappears?
 

ryetee

Registered User.
Local time
Today, 02:36
Joined
Jul 30, 2013
Messages
952
That's weird.

There have been some odd bugs recently with MS updates causing issues? Maybe worth looking at the windows update history and "rolling back" the updates to see if the issue disappears?
OK after investigating the weird issue I found that I'd commented the if me.dirty line and just closed the form!! I'll do that again!
 

Pat Hartman

Super Moderator
Staff member
Local time
Yesterday, 22:36
Joined
Feb 19, 2002
Messages
42,981
The If me.dirty then me.dirty = false is a trick anyway. The actual way to save a dirty record is:

If Me.Dirty Then
DoCmd.RunCommand acCmdSaveRecord
End If

Apparently, under some obscure circumstance, the normal save command causes an error and so many experts have taken to suggesting using the trick all the time insteand of only if you encounter the obscure error.

Access takes it upon itself to save a dirty record when the form closes which is probably why you have survived commenting out the save. Access saved you :)
 

ryetee

Registered User.
Local time
Today, 02:36
Joined
Jul 30, 2013
Messages
952
The If me.dirty then me.dirty = false is a trick anyway. The actual way to save a dirty record is:

If Me.Dirty Then
DoCmd.RunCommand acCmdSaveRecord
End If

Apparently, under some obscure circumstance, the normal save command causes an error and so many experts have taken to suggesting using the trick all the time insteand of only if you encounter the obscure error.

Access takes it upon itself to save a dirty record when the form closes which is probably why you have survived commenting out the save. Access saved you :)
Sorry a pandemic got in the way of this and I just commented the code out on the offending machine.
However need to do it properly now and the above didn't work. Falls over on the "if me.Dirty" bit with error 2455
 

jdraw

Super Moderator
Staff member
Local time
Yesterday, 22:36
Joined
Jan 23, 2006
Messages
15,364
?? are you sure the form is open and you actually have a recordsource??

Seems to be lots of 2455 error references ( via Google) ith various solutions/suggestions.
 

ryetee

Registered User.
Local time
Today, 02:36
Joined
Jul 30, 2013
Messages
952
?? are you sure the form is open and you actually have a recordsource??

Seems to be lots of 2455 error references ( via Google) ith various solutions/suggestions.
Yes the form is open. It doesn't have a recordsource. This code is generated when I use the wizard to close the form - this is when using 2007 2010 or 2016 access. It works in access 2010/2016 but not in 2007. I'm going to get rid of the code but IO like to know why it's failing.
 

missinglinq

AWF VIP
Local time
Yesterday, 22:36
Joined
Jun 20, 2003
Messages
6,423
Yes the form is open. It doesn't have a recordsource.
A Form that doesn't have a RecordSource cannot be Dirty...it has no Bound data...hence the error!

The Microsoft wonks finally fixed an old, old bug:

If one or more Controls on a Form were Required...and DoCmd.Close (used by the Command Button Wizard to Close a Form) was used...the Form would Close but the Record would be dumped!

They finally changed the code behind the Button Wizard
to
Code:
If Me.Dirty Then Me.Dirty = False
   DoCmd.Close

to avoid this bug by forcing a Save which causes the validation/requirement of a Control to accomplished... and it now errors out if you use it to Close an Unbound Form...thus creating a new bug.

Linq ;0)>
 
Last edited:

ryetee

Registered User.
Local time
Today, 02:36
Joined
Jul 30, 2013
Messages
952
Right so the code was introduced on the close button to cover the fact that in most cases a firm is bound?
But!
This doesn't fail in access 2016 and 2010. I only found it because I deployed the code to a machine that runs 2007.
Don't know why I'm surprised!
I'll comment out the code!
 

Users who are viewing this thread

Top Bottom