me.dirty?

G

Guest

I am currently using Access 2007 – when I am creating a form control button
within a form I have a tendency to use the wizard, select the category “form
operations†and the action “close form†– I tend to name the button cmd_close
for each form.

When I try to use the button in the form view I am getting the error message
“You entered an expression that has an invalid reference to the property
Dirty,†this has only started to occur since I switched over to 2007 –
although my default save format is set to Access 2002 -2003.

The script behind the event is:

Private Sub cmd_close_Click()
On Error GoTo Err_cmd_close_Click


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

Exit_cmd_close_Click:
Exit Sub

Err_cmd_close_Click:
MsgBox Err.Description
Resume Exit_cmd_close_Click

End Sub


To avoid this happening I have simply been using a DoCmd.Close behind the
“on click†event and avoiding the wizard all together. I have no idea what
the Me.Dirty expression means – can you give me any pointers? I know enough
to understand the function of the Me part of the expression but despite
searching through books and online cannot find an explanation of the Dirty
part. I have seen this expression in a number of strings and would be
grateful if someone can explain its function and why its preventing me using
a command button created through the wizard in Access 2007.

Many thanks.
 
G

Guest

thanks Paolo - have checked with all other Access 2007 users within my org
and they are also experiencing this prob with the wizard - will log it with
my sysadmin and get them to check with MS on it
 
G

Guest

If the form is UnBounded (No recordset behind it you'll get this error) the
Me.Drity save the record in the form, and if there is no record you can get
the error.

In any case, you can emove this line of code and leave only the close.
As you close the form the record will be saved.

A good place to use this line of code
If Me.Dirty Then Me.Dirty = False

When you want to print a report after you changed values in the form, and
you want this chanes to apear in the report without closing the form, then
this part of code will save the record
 
M

missinglinq via AccessMonster.com

I wasn't aware that ACC2007 was adding this code to it's close buttons, but
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 a validation rule or required
field rule has been violated! If one of these rules has been violated, Access
will simply dump the record, close the form, and not 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.

This code will throw an error, as stated, if the form is unbound, becuase the
form then doesn't have the Dirty property.

--
There's ALWAYS more than one way to skin a cat!

Answers/posts based on Access 2000

Message posted via AccessMonster.com
 
L

Len Robichaud

Have you ever wondered how Undo knows if something Was Done? It's the Dirty
Property.
More often than not (but not always) a form is bound to a recordset (table,
query, sql statement, etc.) so that data can be displayed via the controls
placed on the form. As soon as any bit of that data is changed (i.e.
someone begins to enter or change a piece of data) the form's Dirty Property
is set to True (me.dirty is Boolean). Through this property you can
programmatically test to see if the record needs "saving" before doing
"something".

In your case I'll wager that your form is a Menu of some sort that only
contains command buttons or only displays some data retrieved via DLookup.
Consequently the form has no RecordSource and therfore no Dirty Property to
test so the Wizard's code throws an error. If this is so, just delete "If
Me.Dirty Then Me.Dirty = False".

Len Robichaud
 
M

missinglinq via AccessMonster.com

That will, indeed cause the very error cited, Len!

--
There's ALWAYS more than one way to skin a cat!

Answers/posts based on Access 2000

Message posted via AccessMonster.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top