Command button will not work. Please help! (1 Viewer)

gimes

New member
Local time
Today, 01:15
Joined
Jan 21, 2012
Messages
3
I created a command button choosing form operations, close form. I am getting the following error when I try to use the button:

You enterned an expression that has an invalid reference to a property dirty

Has anyone every seen this? I tried to go to the properties of the button and delete the code. But, I can't create this button without getting this message, even on another form.

Thank you for your time.
 

missinglinq

AWF VIP
Local time
Today, 02:15
Joined
Jun 20, 2003
Messages
6,423
I'm guessing that you're using either Access 2007 or 2010. It has long been recommended that the code

If Me.Dirty Then Me.Dirty = False

be inserted before using

DoCmd.Close


to close a Form because of a quirk in Access. When DoCmd.Close is used, Access closes the Form regardless of whether or not a PK field or other Required Field has been left blank or validation rule has been violated! If one of these things occur, Access will simply dump the Record, close the Form, and not bother to tell the user that the Record has been dumped!

If Me.Dirty Then Me.Dirty = False

forces Access to attempt to save the Record, and if a violation has occurred, will throw up a warning message allowing correction to be made before closing the Form.

After years of not having addressed this bug, I understand that Microsoft sort of fixed it in ACC2007, by adding the above line to force the Save of the Record, when the Wizard is used to create a “Close” button. The problem is that this, in turn, has created another problem (what a surprise!) If you use the Wizard to create a “Close” button for an Unbound Form, which has no Dirty Property, the code bombs out!

Assuming that this is an Unbound Form, you need to either go into the code or, more likely, I'm guessing, the Macro created by the Wizard and remove the

If Me.Dirty Then Me.Dirty = False

line., or simply go into the OnClick event of the Button, delete the Macro completely, and insert the single line of code


DoCmd.Close


Linq ;0)>
 

zip11777

New member
Local time
Today, 02:15
Joined
Jun 29, 2012
Messages
4
I just joined this forum today, searched and found the same error gimes posted.

I applied the fix suggested by missinignq and it worked perfectly ...THANKS!!
 

Users who are viewing this thread

Top Bottom