Solved

How to fix MS Access 2501 ERROR?

Posted on 2014-09-08
4
275 Views
Last Modified: 2014-09-08
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
0
Comment
Question by:cssc1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 37

Assisted Solution

by:PatHartman
PatHartman earned 250 total points
ID: 40310455
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
 
LVL 85

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 250 total points
ID: 40310457
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
 
LVL 37

Expert Comment

by:PatHartman
ID: 40310569
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
 

Author Closing Comment

by:cssc1
ID: 40310741
THanks for the help
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question