Error 2501 the close action was canceled

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


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()
End Sub


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.