Solved

How to fix MS Access 2501 ERROR?

Posted on 2014-09-08
4
272 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 35

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 35

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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

Suggested Solutions

A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.

786 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