473,402 Members | 2,046 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,402 software developers and data experts.

Catch Error 2501

88
Hello,

I have a form in Access for users to do updates from. I'm trying to catch the error 2501 that pops up if they say cancel to the prompt that tells them how many records they are going to update and asks them if they want to continue or cancel.

Here is my code, but it is not working.....

Err_btnUpdate_Click:
If Err.Number = 2501 Then
MsgBox "Update Cancelled.", vbOKOnly
Resume Exit_btnUpdate_Click
Else
MsgBox "Error: " & Err.Number & " Description: " & Err.Description, vbOKOnly
End If

Also, if there isn't a way to get around this, and I just turn the warnings off......is there a way to get the number of records that are going to be updated from an SQL update query executed in the code so that I could display this to the user?

Thank you!

~ Franccesca
Jun 4 '07 #1
3 3589
puppydogbuddy
1,923 Expert 1GB
Hello,

I have a form in Access for users to do updates from. I'm trying to catch the error 2501 that pops up if they say cancel to the prompt that tells them how many records they are going to update and asks them if they want to continue or cancel.

Here is my code, but it is not working.....

Err_btnUpdate_Click:
If Err.Number = 2501 Then
MsgBox "Update Cancelled.", vbOKOnly
Resume Exit_btnUpdate_Click
Else
MsgBox "Error: " & Err.Number & " Description: " & Err.Description, vbOKOnly
End If

Also, if there isn't a way to get around this, and I just turn the warnings off......is there a way to get the number of records that are going to be updated from an SQL update query executed in the code so that I could display this to the user?

Thank you!

~ Franccesca
Franccesca,

You did not explain what you mean by your code "is not working" in this context.

However I think your problem might be that the 2501 error is an openForm failure and does not necessarily have anything to do with clicking the Cancel button in a dialog box, as the 2501 error message states. Actually, I don't believe clicking the cancel button generates an error at all.

So if you are getting a 2501 error OpenForm failure), the first thing I would do is check to see if the dialog (prompt) box that you are calling from btnUpdate is in fact opening. One thing to check is to see if you are able to open the dialog box by itself without code.

If you are not getting a 2501 error, but are trying to trap it because the error message has led you to believe the 2501 error is related to the cancel button....then I would place the code dealing with the click of the cancel button as a separate button click event and code it accordingly.
Jun 4 '07 #2
fperri
88
Sorry,

The form that this is all comming from is a form that allows users to select filters and apply changes to the data in the database. So on the form there is a button for "Update" that they can click once they've selected all their filters and entered in the change. In the update button's click event I execute an SQL statement using the parameters they gave me using:

DoCmd.RunSQL sqlTxt

sqlTxt is my SQL string.

I want the user to be able to see how many records they are going to update so I left the warnings on which makes the message box pop up telling them how many records they are going to update. This is the message box I was talking about.

If the user changes their mind and clicks cancel they get a runtime error 2501 saying "The sql action was cancelled." and it gives you the option to end or debug.

I don't want the user to see this message. I just wanted the code to stop executing so the code I posted above I put in my update button's click event and it was my attempt at catching this error so that I could tell it to exit the sub, that is the part that isn't working, because the runtime error 2501 still pops up, but I'm probably going about it all wrong.

I could probably create a recordset first from the filters to find out how many records are going to be updated, turn off the warnings, use my own textbox with a yes or no, telling them how many records they are going to update - and if they say no exit the sub - and if they say yes run the update query - and do it that way, but I'm thinking that there has got to be a better way.
Jun 20 '07 #3
puppydogbuddy
1,923 Expert 1GB
Sorry,

The form that this is all comming from is a form that allows users to select filters and apply changes to the data in the database. So on the form there is a button for "Update" that they can click once they've selected all their filters and entered in the change. In the update button's click event I execute an SQL statement using the parameters they gave me using:

DoCmd.RunSQL sqlTxt

sqlTxt is my SQL string.

I want the user to be able to see how many records they are going to update so I left the warnings on which makes the message box pop up telling them how many records they are going to update. This is the message box I was talking about.

If the user changes their mind and clicks cancel they get a runtime error 2501 saying "The sql action was cancelled." and it gives you the option to end or debug.

I don't want the user to see this message. I just wanted the code to stop executing so the code I posted above I put in my update button's click event and it was my attempt at catching this error so that I could tell it to exit the sub, that is the part that isn't working, because the runtime error 2501 still pops up, but I'm probably going about it all wrong.

I could probably create a recordset first from the filters to find out how many records are going to be updated, turn off the warnings, use my own textbox with a yes or no, telling them how many records they are going to update - and if they say no exit the sub - and if they say yes run the update query - and do it that way, but I'm thinking that there has got to be a better way.
FPerri,
As I previously stated the 2501 error is an OpenForm failure error, which has nothing to do with cancelling the update as far as I can tell. Unless you are cancelling the opening of a form, you probably have the wrong error #. Nonetheless, as you stated, you can probably suppress the error message by turning the Warnings off.

In regards to your other question about the number of records that are about to be updated......you can copy and paste the SQL string into the sql view of an Access query; then save the query as qryUpdate, and use it as the domain in a Dcount expression that would be the control source of a textbox on your form as shown:

= Dcount(“[KeyField]”, “qryUpdate”)

For more info on the Dcount function see this link:

http://msdn2.microsoft.com/en-us/lib...ffice.11).aspx
Jun 20 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: ColinWard | last post by:
My previous message was blank so Im trying again. I have a button on a form which opens the Import dialogue box. This works fine except if I click on the "X" to close the form I get Run-Time Error...
1
by: Bob Dydd | last post by:
Hi everyone It's me again. I have an access 2000 database with 12 landscape reports which sometimes have to be FAXED and other times printed, so I have written the following code and put it...
5
by: fearblanco | last post by:
Hello - I am receiving the below error message when attempting to open a report. This database is used by approximately 20 users and only one user is having this problem (even I can't duplicate...
3
by: Ed Robichaud | last post by:
I'm temporarily stumped on how to handle/suppress an error (2501) if a user cancels sending an email. I'm using DoCmd.SendObject to trigger an Outlook send window, which works OK, but if the msg...
4
by: Keith | last post by:
I have the following code in the On No Data event of a report: **** On Error GoTo err_trap MsgBox "No items matching criteria.", vbInformation, gcApplication Cancel = True err_trap: If...
33
by: Anthony England | last post by:
I am considering general error handling routines and have written a sample function to look up an ID in a table. The function returns True if it can find the ID and create a recordset based on...
7
by: Keith Wilby | last post by:
In an old A97 app I trap for error 2501 in a report's calling code just in case there are no records to return (set cancel = True in the report's No Data event). This doesn't seem to work in my...
8
by: sara | last post by:
I have a report that runs fine with data. If there is no data, I have its NO Data event sending a MsgBox and cancelling the report. Then it seems I still get the 2501 message on the Open Report...
7
sassy2009
by: sassy2009 | last post by:
Hello, I am running an insert query from xl spreadsheet using the DoCmd.RunSQL to insert values from the spreadsheet into the Access database. When i run this query it gives an error saying "...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.