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 " Run-time error 2501 RunSQL action was cancelled".
I know why this is happening and it's because of the message box that appears when an action query is run in Access which asks for a confirmation from the user "yes" or "no" buttons. But when i run the query from Spreadsheet, Access assumes "no" for the message box and cancels the RunSQL. How do I handle this error. If I ran the same query in Access itself it gives me the same "2501" error when I clicked on the "NO" button. Please help.....
7 15908 topher23 234
Recognized Expert New Member
Your best bet is to turn off confirmation for action queries. Open an Access database, then go to Tools > Options. Click on the Edit/Find tab and, near the top left corner, you'll see the "Confirm" group. Uncheck "Action queries." In all of my projects, I only keep "Document deletions" checked.
If the problem is indeed that dialog box, this should take care of your issue.
Edit: FYI, what you are doing is called "pushing" the data. I generally use "pulling," in which I already know which Excel fields I want, so I run the code from Access and have it "pull" the data from the Excel spreadsheet. That way I don't have to have the Excel spreadsheet open in order to run my code, since I'm going to do my manipulation and reporting from Access anyway.
NeoPa 32,560
Recognized Expert Moderator MVP
This is hard to answer as you fail to give much information as to what is running from where.
Generally, you won't see this message unless you've already seen the prompt for allowing the query to run. I suspect something is not as you say, yet what that may be is impossible to tell with so little detail in your question.
As a general rule though, there should be no need to change the settings as you currently choose to have them, for this issue.
Hello,
This is my actual code in excel which is used to add new data to the table. - Private Sub CommandButton1_Click()
-
-
Dim appaccess As Access.Application
-
Dim dbstr As String
-
-
Set appaccess = GetObject("C:\Users\sassy\Documents\BillTracking.accdb", "Access.Application")
-
appaccess.Visible = False
-
appaccess.DoCmd.RunSQL "INSERT INTO tblWorkload VALUES ('JEN1','username', 100, #11/03/2009# )"
-
-
-
End Sub
But if i run this query in access it works fine without any message box popping as i have unticked the confirm action queries from Access Options. But when i run from excel the 2501 error pops up and says RunSQL action was cancelled.
Please help.....
Hello all,
I dont know what was wrong with my previous code which i posted last time. As far as i know if i find a way to handle the confirmation message from Access then my insert SQL statement should work fine. But i was going crazy as i couldnt fix this and jumped on youtube to watch some movie trailers. After a while i just searched for "integrating Excel and Access using VBA" on youtube and found this code which worked absolutely superbbbbbbbbbbb.
This is my new code and the values are getting updated into database without any problems. But still i cant find an answer why my previous insert statement says "RunSQL action was cancelled" and the new code doesnt. - Private Sub CommandButton1_Click()
-
-
Dim con As New ADODB.Connection
-
Dim sql As String
-
-
With con
-
.Provider = "Microsoft.ACE.OLEDB.12.0"
-
.connectionString = "Data Source=C:\Users\sassy\Documents\BillTracking.accdb;"
-
.Open
-
End With
-
-
-
sql = "INSERT INTO tblWorkload VALUES ('JEN1','username', 500, #11/03/2009# )"
-
con.Execute sql
-
MsgBox "Values entered", vbInformation
-
con.Close
-
Set con = Nothing
-
-
End Sub
topher23 234
Recognized Expert New Member
Well, the reason the new code doesn't have the same issue is easy enough to be seen here. With the old code, you actually opened an instance of Access in order to enter your data, which triggered the confirmation dialog for the action query. In the new code, you are referencing your database as a data source without actually opening Access, thus bypassing any protections built into Access. Therefore, the new code doesn't trigger the confirmation dialog, since there is no instance of Access open for it to trigger from. @sassy2009
Well, strike that stuff about dialog boxes, I just found your answer. When you have an open Excel workbook in Office 2007, and the workbook opens an Access instance, it apparently opens the database as read-only! No one on any other forum had any suggestions of how to make it not do this. So, the code you found is the only code that will work in this case, as it doesn't actually open Access.
I know it is an old thread, but I was happy to find it. Although no solution was mentioned it gave me an idea.
The error is due to the Application.SecurityAutomation that is not set to "low" on forehand.
If you never accessed the file manually then it is not a trusted document for you yet and the run time error appears.
Hence, 2 alternatives:
1. You manually open it, enable content and make it a trusted document and then do your thing in VBA.
2. Or: before you start the query, insert: - Set xApp is Object 'Late binding
-
Set xApp = CreateObject("Access.Application")
-
xApp.AutomationSecurity = msoAutomationSecurityLow
-
-
'your query code goes here
-
-
xApp.AutomationSecurity = msoAutomationSecurityByUI
-
'or whatever it was before you started
NeoPa 32,560
Recognized Expert Moderator MVP
There's no problem posting alternative or new answers to old threads. The problems only occur when a new poster wants to add their own question to the mix.
I'm pleased to see this was of some help triggering your thought processes :-)
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: James |
last post by:
Hi,
I would like to run a custom script on a linux box via a button on a php
page (php webpage hosted on the same linux box).
Is this possible? If so , can you give me a pointer in the right direction?
thanks
James
|
by: leroybt.rm |
last post by:
Can someone tell me how to run a script from a interactive shell
I type the following:
>>>python filename
>>>python filename.py
>>>run filename
>>>run filename.py
>>>/run filename
>>>/run filename.py
|
by: Ed |
last post by:
Hello,
I took a course in asp about 2 years ago and I was
practicing with IIS 5.0. Then I put it down for a while.
Now trying to get back to it. I can't run asp files from
subdirectories of my root directory, but I can run asp
files from the root directory of my website and I can run
htm files from the subdirectories. If I run
...
|
by: Jenna Olson |
last post by:
Hi all-
I've never seen this particular issue addressed, but was wondering if
there's anything to support one way or another. Say I have a class:
class ManipulateData
{
public:
ManipulateData(const char* Path-To-Some-Text-File)
{ ... }
|
by: Napo |
last post by:
Hi:
i build a .net application named A.exe. I need run this application
twice using c# code in another application. i try to use
process.start(A.exe) twcie, but it failed. Because the second start will use
the existed process. So only one application run.
I can use mouse to run this application twice, and there are two A.exe
processes in...
| |
by: orekin |
last post by:
Hi There
I have been trying to come to grips with Application.Run(),
Application.Exit() and the Message Pump and I would really appreciate
some feedback on the following questions .. There are quite a few
words in this post but the questions are actually quite similar and
should be fairly quick to answer ...
(1) What is Happening with...
|
by: Bob Day |
last post by:
Using vs2003, vb.net
I start a thread, giving it a name before start. Code snippet:
'give each thread a unique name (for later identification)
Trunk_Thread.Name = "Trunk_0_Thread"
' allow only 1 thread per line
Trunk_Thread.ApartmentState = ApartmentState.STA
|
by: Brett Wesoloski |
last post by:
I am new to VS2005.
I changed my program.cs file to be a different form I am working on. But
when I go to run the application it still brings up the form that was
originally declared as new. When I put in a break point the program does
not stop. It is in debug mode. If I change the program.cs file back to the
form that was originally...
|
by: David Thielen |
last post by:
Hi;
In our setup program how do I determine if I need to run "aspnet_regiis –i"
and if so, is there an API I can calll rather than finding that program on
the user's disk and calling it?
--
thanks - dave
david_at_windward_dot_net
http://www.windwardreports.com
|
by: traceable1 |
last post by:
Is there a way I can set up a SQL script to run when the instance
starts up?
SQL Server 2005 SP2
thanks!
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
| |
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |