Vba ошибка 2501

I’ve been asked to make some modification to Forms in an Access database used by a group I work with. I had to add a data entry form similar to one that exists so I copied one of the existing forms and made some modifications. When I click the button to open the form to test it I get this error:

Run-time error ‘2501’
The OpenForm action was cancelled.

Here is the code that is called to cause this error:

Private Sub cmdCPE_EntryForm_Click()
On Error GoTo Err_cmdCPE_EntryForm_Click

    Dim stDocName As String
    Dim stLinkCriteria As String

    stDocName = "CPE_EntryForm"
    DoCmd.OpenForm stDocName ', , , stLinkCriteria

Exit_cmdCPE_EntryForm_Click:
    Exit Sub

Err_cmdCPE_EntryForm_Click:
    MsgBox Err.Description
    Resume Exit_cmdCPE_EntryForm_Click

End Sub

Thx in advance for any assitance.

asked May 13, 2016 at 13:34

JasonR's user avatar

2

the form you’re trying to open is in design view. Close design view

answered Aug 13, 2018 at 14:51

Carl's user avatar

CarlCarl

212 bronze badges

0

I got this error when my form was referring to a query that no longer existed.
Once I updated the form to point to an existing query, my code worked fine.

answered Jul 21, 2017 at 12:01

Michael's user avatar

1

My form open error 2501 «Form Open Cancelled» error in MSAccess was due to the form’s data source table not existing.

answered Feb 23, 2021 at 19:36

BigT's user avatar

0

Runtime Error 2501 can occur on calling the OpenForm method if there is a problem with the database.

Try following the steps in this link under the headings «Recovering from corruption» and «Symptom: Cannot open a form or report»?

http://allenbrowne.com/ser-47.html

Could also be a problem with the new form’s Open or Load events, might be worth posting that code as well for review.

answered May 13, 2016 at 13:40

Dave's user avatar

DaveDave

4,3282 gold badges24 silver badges33 bronze badges

1

I had exactly the same error when I wanted to open a form containing a sub form whose data was located in another folder. By decreasing the path of the dorsal base this has repaired the error. For example, the first path was C:DevApplicationVers1ProgDebugmyAppDB.accdb, so I decreased the path’s length in : C:DevDebugmyAppDB.accdb and this solved the problem. The same error occurred with a network path, and I fixed it with the same method.

By assuming that you have :
a command button named «cmdOpenForm» and
a form called: «myForm»

I have also add this code on the On Click Event of the command button :

Private Sub cmdOpenForm_Click()
On Error GoTo Err_cmdOpenForm_Click
    If CurrentProject.AllForms("myForm").IsLoaded = True Then
        DoCmd.Close acForm, "myForm"
    Else
        DoCmd.OpenForm "myForm", acNormal, , , , acWindowNormal, Me.Form.Name
    End If
Exit_cmdOpenForm_Click:
Exit Sub
Err_cmdOpenForm_Click:
MsgBox "Error number : " & Err.Number & vbCrLf & "Error: " & Err.Description, vbCritical
Resume Exit_cmdOpenForm_Click
End Sub

answered Jan 25, 2018 at 11:54

Djamel's user avatar

Your RecordScorce is not recognized. Type your recordScource In Code, then in Menu ToolReference Change place of your references.Then Debug your project And then save it.

sanyassh's user avatar

sanyassh

8,03013 gold badges36 silver badges66 bronze badges

answered May 11, 2019 at 9:41

Mansoor Bozorgmehr's user avatar

Try closing the forms that you want to open then rerun the code. Worked for me.

answered Mar 16, 2022 at 2:05

Meeeep's user avatar

Background:

I’ve been working on a macro to post company reports to out SharePoint site. The code runs in an instance of Access 2016. It works if I change the filelocation to one of my local drive, but not the Sharepoint site. I’ve spent days researching the error, but none of the results apply, and none of the fixes work.

Code:

Function CopySJIToWeb()


Dim fileLocation As String, fileName As String
Dim counter As Integer, i As Integer, store As Integer
Dim nstores(4) As Integer

nstores(0) = 31
nstores(1) = 37
nstores(2) = 41
nstores(3) = 44
nstores(4) = 57

FileName = "12 Dec 2015 Sales Journal.pdf"
counter = 1
store = 1

Do While counter < 59
     FileLocation = "http://192.168.100.12/holiday store " & store & "/holiday " & store & " sales journals/"
     DoCmd.OutputTo acOutputReport, "Sales Journal", acFormatPDF, FileLocation & FileName, True, "", 0, acExportQualityPrint
     SendKeys counter
     SendKeys "{ENTER}"
     counter = counter + 1
          If counter > 2 Then
               store = store + 1
          End If
          If store > 30 Then
               For i = 0 To 4
                    If store = nstores(i) Then
                    store = store + 1
                    End If
               Next i
           End If    
Loop

End Function

Running this throws the error: «Runtime error 2501. The OutputTo action will be cancelled.»

My office account has the necessary permissions and in my browser I’m logged in as said account, so I can’t see permissions being the issue. The network location is correct, and I’ve tried using both the ip address and site’s name in the file location. I’ve made sure there are no non existent spaces or other characters. I’ve also tried using %20 instead of spaces in the filename, in case those spaces were being stripped. Microsoft’s documentation of the 2501 runtime error has been incredibly unhelpful.

So what causes this error? What specifically is happening underneath it all? And what are other ways to resolve it?

  • Remove From My Forums
  • Question

  • I have the following code snipit that saves any open reports to a subdirectory as a .pdf file and then closes the report window. It runs VERY inconsistantly. Sometimes it works fine, other times I get the dreaded Runtime 2501 error that tells me the
    OutPutTo operation has been cancelled. I cannot find any common cause. Sometimes the reports have only 1 page and sometimes >1. Sometimes there is only one report open and sometimes >1. If >1 report is open, sometimes it cycles through
    the routine for some of the reports and then quits halfway through. So it is not the code. I have a funny feeling it may be related to cashe memory somehow.

    Is there some vba command that can flush memory after the report window closes? I am at a loss because of the inconsistant behavior.

    Dim obj As AccessObject, dbs As Object
    Set dbs = Application.CurrentProject
    Dim ReportName As String
        For Each obj In dbs.AllReports
            If obj.IsLoaded = True Then
                ReportName = obj.FullName
                On Error GoTo EMailAllReprtspdf_Error
                DoCmd.OutputTo acOutputReport, , acFormatPDF, «C:Reports» & ReportName & «.pdf», 0, , , acExportQualityScreen
                DoCmd.Close                  (Should I flush memory somehow here?)
            End If
        Next obj

    Thanks for any suggestions.

    Larry

Answers

  • The following code IS working now without problems so far. The DoEvents command does not throw an error now either like it did before.

        For Each obj In dbs.AllReports
            If obj.IsLoaded = True Then
                ReportName = obj.FullName
                DoCmd.SelectObject acReport, ReportName
                DoCmd.OutputTo acOutputReport, ReportName, acFormatPDF, «C:ORCASReports» & ReportName & «.pdf», 0, , , acExportQualityPrint
                DoEvents
            End If
        Next obj

    The problem has to have been the missing SelectObject command. I can even leave the reports all open and send them in .xps format as well with no problems so far. The
    OutputTo command needs the object selected to work properly.

    I am sure Dirk’s suggestion will work as well. There are so may ways VBA can be used and so many different commands that do similar things, I sometimes have a hard time with it.

    My thanks to all of you for your kind and helpful suggestions. I try my best to help others as well, although I am really sort of a beginner.

    • Proposed as answer by

      Wednesday, March 9, 2011 9:00 AM

    • Marked as answer by
      Lawrence Ellefson
      Wednesday, March 9, 2011 2:11 PM

Icon Ex Error Number: Error 2501
Error Name: The | action was canceled
Error Description: The | action was canceled.@You used a method of the DoCmd object to carry out an action in Visual Basic, but then clicked Cancel in a dialog box.For example, you used the Close method to close a changed form, then clicked Cancel in the dialog box that ask
Developer: Microsoft Corporation
Software: Microsoft Access
Applies to: Windows XP, Vista, 7, 8, 10, 11

The | action was canceled Assessment

Experts generally refer to The | action was canceled as a «runtime error». Developers like Microsoft Corporation usually go through several checkpoints before launching a software program like Microsoft Access. Tragically, problems like error 2501 can be missed, and the software will contain these problems on release.

Error 2501 might be faced by Microsoft Access users if they are using the program regularly, also seen as «The | action was canceled.@You used a method of the DoCmd object to carry out an action in Visual Basic, but then clicked Cancel in a dialog box.For example, you used the Close method to close a changed form, then clicked Cancel in the dialog box that ask». In the event of the detected error 2501, customers may convey the presence of problem to Microsoft Corporation via email or bug reporting. They will then patch the defective areas of code and make an update available for download. This situation happens due to Microsoft Access software upgrades being one of the solutions for error 2501 errors and other problems.

Why Does Runtime Error 2501 Happen?

A problem with Microsoft Access source code will produce this The | action was canceled, most often during the startup phase. Let’s analyze some of the most common causes of error 2501 runtime errors:

Error 2501 Crash — This is a typical runtime error 2501 error that crashes the machine entirely. This emerges when Microsoft Access fails to respond to input properly, or does not know what output is required in return.

The | action was canceled Memory Leak — When a Microsoft Access Memory leak occurs, this can result in the device running slow due to system resources running short. It may be triggered by the misconfiguration of the software by Microsoft Corporation, or when one command starts a loop which can’t be ended.

Error 2501 Logic Error — Logic error happens when the PC produces the wrong output, even when the user enters the right input. This can happen when Microsoft Corporation’s source code has a vulnerability regarding data handing.

The root causes of Microsoft Corporation errors associated with The | action was canceled include a missing or corrupt file, or in some cases, a past or present Microsoft Access-related malware infection. A large percentage of these file issues can be resolved with downloading and installing the latest version of your Microsoft Corporation file. We also recommend running a registry scan to clean up any invalid The | action was canceled references which could be cause of the error.

Typical The | action was canceled Errors

Typical The | action was canceled Errors That Occur in Microsoft Access for Windows:

  • «The | action was canceled Error.»
  • «The | action was canceled not a Win32 program.»
  • «Sorry for the inconvenience — The | action was canceled has a problem.»
  • «The | action was canceled can’t be located.»
  • «The | action was canceled can’t be found.»
  • «Error starting program: The | action was canceled.»
  • «Can’t run The | action was canceled.»
  • «The | action was canceled failure.»
  • «Faulty Program Path: The | action was canceled.»

The | action was canceled EXE errors happen during Microsoft Access installation, while running The | action was canceled-related applications (Microsoft Access), during startup or shutdown, or during installation of Windows OS. It’s important to note when The | action was canceled issues happen, as it helps troubleshoot Microsoft Access problems (and report to Microsoft Corporation).

Origins of The | action was canceled Troubles

The | action was canceled problems can be attributed to corrupt or missing files, invalid registry entries associated with The | action was canceled, or a virus / malware infection.

In particular, The | action was canceled problems originate through:

  • The | action was canceled registry keys invalid / corrupted.
  • Virus-contaminated and corrupted The | action was canceled.
  • The | action was canceled mistakenly deleted or maliciously by software unrelated to the Microsoft Access application.
  • A different application in conflict with The | action was canceled, or other shared references.
  • Microsoft Access / The | action was canceled corrupt from incomplete download or install.

Product by Solvusoft

Download Now
WinThruster 2023 — Scan your PC for computer errors.

Compatible with Windows 11, 10, 8, 7, Vista, XP and 2000

Optional Offer for WinThruster by Solvusoft | EULA | Privacy Policy | Terms | Uninstall

The error 2501 can occur on calling On Close event of report, if there is a problem with the database. While working with reports and Forms error 2501 can be occur, if database go corrupted or changed. There are many reasons for this error like as row deletion in database or changed, data source key field is no longer primary key and relationships are gone, Network Connect Lost of data source etc.

In this article firstly we are reproducing this error, and then resolving this. To reproduce this error we need create report that has data source table. When we open the report in report view, it will show all the data of table. Suppose suddenly there is change in data of table and simultaneously we close report, then an error message will pop up, Run time error 2501; the close action was cancelled as shown in Fig 1.1.

Error 2501 the close action was canceled Fig-1.1

Fig:-1.1

For that we have also write code for close report on, Close event of report. We can avoid this error by using error handling technique, performing step by step action on database and maintain backups. In our case we have to save the report on close event.

VBA code on close event of report:

Option Compare Database
Private Sub Report_Close()
DoCmd.Close
End Sub


DISCLAIMER

It is advised that the information provided in the article should not be used for any kind formal or production programming purposes as content of the article may not be complete or well tested. ERP Makers will not be responsible for any kind of damage (monetary, time, personal or any other type) which may take place because of the usage of the content in the article.


Понравилась статья? Поделить с друзьями:
  • Vba ошибка 1004 при открытии файла
  • Vba отключить проверку ошибок
  • Vba обработчик ошибок on error
  • Vba обработка ошибок err
  • Vba номер строки ошибки