?
Solved

How to fix MS Access 2501 ERROR?

Posted on 2014-09-08
4
Medium Priority
?
278 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 38

Assisted Solution

by:PatHartman
PatHartman earned 1000 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 1000 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 38

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: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
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.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

752 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