Access save bound form record

I have this: -

 If Me.Dirty = True Then
  DoCmd.RunCommand acCmdSave
 End If

Open in new window


It gives error 2455 "You entered an expression that has an invalid reference"

I am trying to get a bound form to save after a box is ticked. Can anyone help?
HKFueyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Gustav BrockCIOCommented:
Try with:

 If Me.Dirty = True Then
     Me.Dirty = False
 End If

/gustav
0
mbizupCommented:
Try acCmdSaveRecord

If Me.Dirty = True Then
  DoCmd.RunCommand acCmdSaveRecord
 End If

Open in new window

0
HKFueyAuthor Commented:
Sorry for not being clear, it errors on line 1

 If Me.Dirty = True Then
0
10 Tips to Protect Your Business from Ransomware

Did you know that ransomware is the most widespread, destructive malware in the world today? It accounts for 39% of all security breaches, with ransomware gangsters projected to make $11.5B in profits from online extortion by 2019.

IrogSintaCommented:
If this code is in the AfterUpdate event of the checkbox then I don't think you need to test for Dirty since Dirty would always be True whenever this box is checked or unchecked. You can just use:
Dirty = False
0
mbizupCommented:
Where is your code located?

If it is not on the form, you'll need the full reference:

Forms!YourFormName.Dirty
0
HKFueyAuthor Commented:
Hi mbizup,

Tried the form name, I still get the error, if I take out the if statement and just leave: -

DoCmd.RunCommand acCmdSaveRecord

It seems to work OK
0
mbizupCommented:
There should be no issue with "If Me.Dirty then...", assuming that the code is on the same form...

There also should be more to that error message than what you posted.  It should be something along the lines of "You entered an expression that has an invalid reference to the property {some property}"

Does the error message actually specify a property name (such as 'Dirty') or is it simply something like "|"?  If it is the latter, this by Allen Browne suggests corruption:

http://www.tech-archive.net/Archive/Access/microsoft.public.access.forms/2004-12/0268.html

And recommends:
- Turning OFF name autocorrect if it is on
- decompiling/compiling
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mbizupCommented:
Just for kicks, try the same thing on a new (or different) form.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.