Solved

How to fix MS Access 2501 ERROR?

Posted on 2014-09-08
4
266 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
  • 2
4 Comments
 
LVL 34

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 84

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 34

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

In Debugging – Part 1, you learned the basics of the debugging process. You learned how to avoid bugs, as well as how to utilize the Immediate window in the debugging process. This article takes things to the next level by showing you how you can us…
QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

757 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now