How to fix MS Access 2501 ERROR?

For some reason on the form "Events_1of2_frm" when I click the far left hand side of the form I get a 2501 error.

Can't figure out why?

Any help is appreciated.

The error is 100% recreatable
RC-Ver1-Good.zip
3ERROR-2501---2.jpg
ERROR-2501---1.jpg
ERROR-2501---1.jpg
cssc1Asked:
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.

PatHartmanCommented:
You can't fix the error.  You have to trap for it and ignore it.  The most common instance is if you have validation code in the Form's BeforeUpdate event that will cancel the save if the validation fails.  That will cause the calling procedure to receive the 2501 error.  So, add error trapping to the calling procedure and ignore the 2501.  The error also happens if you have code in the NoData event of a report that cancels opening the report.  So look for situations where you use DoCmd.anything and if those procedures can be cancelled, expect a 2501.
0
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
The record isn't dirty when you try to save, so you either (a) introduce code to NOT save unless the form is Dirty or (b) consume the 2501 error and ignore it. IMO, (a) is the easier way:

Instead of

DoCmd.RunCommand accmdsaveRecrd

Use

If Me.Dirty Then Me.Dirty = False
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
PatHartmanCommented:
Scott,
The Me.Dirty = False trick also raises an error if the save is cancelled.  It is just not 2501.  It is 2101.

Create a test form bound to a test table and add two buttons and cancel the save in the beforeUpdate event.
Option Compare Database
Option Explicit

Private Sub cmdDirtyFalseMethod_Click()
    Me.Dirty = False
End Sub

Private Sub cmdDoCmdmethod_Click()
    DoCmd.RunCommand acCmdSaveRecord        
End Sub

Private Sub Form_BeforeUpdate(Cancel As Integer)
    Cancel = True
End Sub

Open in new window


I call Me.Dirty = False a trick (so I always add a comment if I use it) because if you asked a dozen people who had never seen it before what it did, I would expect more than half would guess that it canceled the save rather than forced it whereas acCmdSaveRecord is pretty clear.
0
cssc1Author Commented:
THanks for the help
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
Microsoft Access

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.