In some places I have left the warning messages enabled for the users. If they click cancel they get an error.
How do you add code to this event. I have traced through the program, but I never see the code that actually fires this warning message.
The error is 2501, runSQL action was canceled.
Thanks in advance for the help
15 4899 NeoPa 32,556
Expert Mod 16PB
You have (accidentally) posted this question in the Access Articles section. This is NOT an article.
I'm moving this to the main Access questions forum.
MODERATOR.
NeoPa 32,556
Expert Mod 16PB
I don't know the answer to this but I may well know a man who does ;)
I'll PM him the link if you can wait for his response.
In some places I have left the warning messages enabled for the users. If they click cancel they get an error.
How do you add code to this event. I have traced through the program, but I never see the code that actually fires this warning message.
The error is 2501, runSQL action was canceled.
Thanks in advance for the help
If I interpret your question correctly, you are referring to the display of System Messages and the subsequent '2501' Error that Access generates when the User decides not to run an Action Query. If this is the case, then the SetWarnings Method of the DoCmd Object is what you are looking for. A simple code block will illustrate this point: - Dim MySQL As String
-
MySQL = "DELETE tblDelete.* FROM tblDelete;"
-
-
'Turn OFF the display of the Deletion Prompt. You will receive no warning and
-
'will not be able to Cancel the Delete Operation once it has been committed.
-
DoCmd.SetWarnings False
-
'Can be ANY type of Action Query
-
DoCmd.RunSQL MySQL
-
DoCmd.SetWarnings True 'must manually Reset to be turned ON again
Is this what you are looking for? NeoPa 32,556
Expert Mod 16PB
I thought the OP was asking about customising error messages, but your interpretation could as easily be correct. The question is not clear and it's hard to guess what he's actually asking :(
I thought the OP was asking about customising error messages, but your interpretation could as easily be correct. The question is not clear and it's hard to guess what he's actually asking :(
I was kind of hazy myself, especially because I knew that you were aware of SetWarnings. How about we just sit back, relax, and wait for a response from the OP?
NeoPa 32,556
Expert Mod 16PB
sorry it has been so long, life has a way of happening....
I will try to be more clear.
For the database settings I have checked both boxes for delete warnings and add warnings.
In most cases I have managed the warnings by turning them off and on with no issues.
When a user wants to create a new object I display the nessecary text boxes to collect all the data to enter into the table.
ie new employee (firstname, last name, type)
The user then clicks a button, if one field is missing I send a msgbox to them telling them to fill all fields. If all fields are filled Access tells them they are about to append a row. If they click no I get the error 2501. If they click yes the data is inserted into the table.
I do want the access message to show.
What I am wondering is how to code the no button click on the Access generated msgbox.
I know I could just disable all warning messages in the database and then create my own and code those button clicks with a Select case msgbox.
I was hoping to not have to add a bunch of these message boxes. I would rather just code the no button on the Access messagebox.
Hopefully this is more clear
Thanks to all (sorry for posting in wrong place)
Are you looking for something along the lines of this?: - If MsgBox("[YourMessageText", vbYesNo + vbDefaultButton1) = vbNo Then
-
DoSomething
Regards,
Scott
That seems like code for a custom message box ( I do have several of those)
Does that work for Access generated warning messages
for example when you add a record with warning messages enabled access generates a warning message box that you are about to append one record.
It displays a yes and a no button. I need to code the no button.
When I trace the code : - sSQL = "INSERT INTO Lookup_Airtanker (AirTankerID, Type, IsValid)"
-
sSQL = sSQL & "VALUES ('" & DataEntryTextbox.Value & "', '" & FirstNameTextbox.Value & "', true)"
-
DoCmd.RunSQL (sSQL)
the Do.cmd.RunSQL(sSQL) line highlights then brings up a message box. If I click yes it leaves the Docmd line and continues through code
if i click no I get the error 2501 (as mentioned above)
If that is the code to handle the access generated message then where do I put it?
About your question, I'm not sure about the access warning/error message boxes, whether you can (nor how you can), refer to them in vb code, aside from maybe exploring the On Error Goto Error_Handler. You would then have to trap the error number, and then write a corresponding If...Then statement for when it corresponds to the 2501 message.
Simpler than the above would be to simply write the - If MsgBox(YourOriginalMessageBox) = vbNo Then
-
DoCmd.SetWarnings = False
-
'Add custom message box that emulates the Access generated one
-
DoCmd.SetWarnings = True
-
End If
Don't think I can help you any further than this! Sorry...
Regards,
Scott
sorry it has been so long, life has a way of happening....
I will try to be more clear.
For the database settings I have checked both boxes for delete warnings and add warnings.
In most cases I have managed the warnings by turning them off and on with no issues.
When a user wants to create a new object I display the nessecary text boxes to collect all the data to enter into the table.
ie new employee (firstname, last name, type)
The user then clicks a button, if one field is missing I send a msgbox to them telling them to fill all fields. If all fields are filled Access tells them they are about to append a row. If they click no I get the error 2501. If they click yes the data is inserted into the table.
I do want the access message to show.
What I am wondering is how to code the no button click on the Access generated msgbox.
I know I could just disable all warning messages in the database and then create my own and code those button clicks with a Select case msgbox.
I was hoping to not have to add a bunch of these message boxes. I would rather just code the no button on the Access messagebox.
Hopefully this is more clear
Thanks to all (sorry for posting in wrong place)
What I am wondering is how to code the no button click on the Access generated msgbox
To the best of my knowledge, this is intrinsic to Access and cannot be modified!
Thank you that answers my question. I guess it is custom message box coding heaven I'll have to delve into.
Thanks for all that tried to help with this, sorry for not being clear off the top.
It does make me feel a little better that it can't be done, as I couldn't figure it out on my own.
Would catching the 2501 error help you any? I.e.:
On Error GoTo Err_Label
'
' all your sub's code goes here
'
Err_Label: If Err.Number = 2501 Then'
'The Run SQL action was canceled...
'put your code for the 'no' button here
' End if
MsgBox Err.Description End Sub
Would catching the 2501 error help you any? I.e.:
On Error GoTo Err_Label
'
' all your sub's code goes here
'
Err_Label:If Err.Number = 2501 Then'
'The Run SQL action was canceled...
'put your code for the 'no' button here
' End if
MsgBox Err.Description End Sub
It probably would indirectly accomplish what you want, although might take some tweaking to get it just right. Have you tried it out yet?
Regards,
Scott
jfkiser has the right idea. Assuming the button to run this query was generated by the command button wizard, you've got an error handler at the bottom of your sub. Your sub should look something like this, where the name of your command button should be everywhere that you see RunYourQuery in this code. - Private Sub RunYourQuery_Click()
-
On Error GoTo Err_RunYourQuery_Click
-
-
Dim stDocName As String
-
-
stDocName = "YourQueryName"
-
DoCmd.OpenQuery stDocName, acNormal, acEdit
-
-
Exit_RunYourQuery_Click:
-
Exit Sub
-
-
Err_RunYourQuery_Click:
-
If Err.Number = 2501 Or Err.Number = 2001 Then
-
Resume Exit_RunYourQuery_Click
-
Else
-
MsgBox Err.Description
-
Resume Exit_RunYourQuery_Click
-
End If
-
End Sub
To turn the error message off (which you said you wanted to do) for this problem but leave other error detection intact, replace the error handler with Lines # 12 - 18, as above.
Amazingly, if you only trap error 2501, Access will sometime, not always, throw a second error, 2001, which also means that an operation has been cancelled.
Linq ;0)> Sign in to post your reply or Sign up for a free account.
Similar topics
by: Montrose... |
last post by:
After working in c# for a year, the only conclusion I can come to is
that I wish I knew c.
All I need is Linux, the gnu c compiler and I can do anything.
Web services are just open sockets...
|
by: Random Person |
last post by:
Does anyone know how to use VBA to relink tables between two MS Access
databases? We have two databases, one with VBA code and the other with
data tables. The tables are referenced by linked...
|
by: Daveyk0 |
last post by:
Hello there,
I have a front end database that I have recently made very many changes
to to allow off-line use. I keep copies of the databases on my hard
drive and link to them rather than the...
|
by: Susan Bricker |
last post by:
Hi.
I have a routine for the AfterUpdate event of a checkbox on my Main
Menu. The checkbox causes a "User Variable" (in a table for
UserSettings) to be modified ('Y' or 'N') by issuing an...
|
by: Skybuck Flying |
last post by:
Hi,
I needed a method to determine if a point was on a line segment in 2D. So I
googled for some help and so far I have evaluated two methods.
The first method was only a formula, the second...
|
by: dbuchanan |
last post by:
Hello,
>From time to time my vb2005 form disappears and is replaced by the
following errors. Rebuilding the application never helps. However the
errors never affects the operation of my...
|
by: genc ymeri |
last post by:
Hi over there,
I'm building a webservice (C#/>Net 1.1) and I'm trying to add a web
reference , a WSDL file from a location "c:\inetpub\WSDLfile.wsdl" . (This
is the WSDL file of another webserver...
|
by: Peter Ritchie [C# MVP] |
last post by:
I've purposely been ignoring a CA2122 warning in some C++ interop code I've
been working on for quite some time. I've just recently had the cycles to
investigate the warning. The warning message...
|
by: Ivan Vecerina |
last post by:
Here's a relatively simple code snippet:
#include <memory>
class Base {
public:
Base();
virtual ~Base();
virtual void f(int a, char const* name);
|
by: Ian |
last post by:
I've just discovered the msclr::lock class in the C++ Support Library online
documentation. This seems like a much cleaner way to implement thread
protection than using...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
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
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| |