473,770 Members | 2,069 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Whats is the Transactional difference between Docmd.RunSQL and CurrentDb.Execu te SQL?

TheSmileyCoder
2,322 Recognized Expert Moderator Top Contributor
I have been playing around with transactions and one thing got me wondering. First is the code I am using:

Expand|Select|Wrap|Line Numbers
  1. 'Start transaction
  2.         'Get default Workspace.
  3.             Dim wrkDefault As Workspace
  4.             Set wrkDefault = DBEngine.Workspaces(0)
  5.  
  6.         'Start of transaction
  7.             wrkDefault.BeginTrans
  8.             Dim strSQL As String
  9.             strSQL = "UPDATE tbl_Trans SET tx_Field='jjj' WHERE ID=2"
  10.             'DoCmd.RunSQL strSQL
  11.             CurrentDb.Execute strSQL
  12.             If vbYes = MsgBox("Commit changes?", vbYesNo) Then
  13.                 wrkDefault.CommitTrans
  14.                 Else
  15.                 wrkDefault.Rollback
  16.             End If
Now If I use CurrentDB.Execu te strSQL then it works as expected and rolls back the changes I made.
However, If I use DoCmd.RunSQL strSQL the rollback does not take effect.

Now I have also tried both:
Expand|Select|Wrap|Line Numbers
  1. DoCmd.RunSQL strSQL,True
  2. DoCmd.RunSQL strSQL,False
With the same results.

Can anyone explain this, or point out something I am missing?
Apr 26 '11 #1
4 9966
ADezii
8,834 Recognized Expert Expert
Not sure about the RunSQL approach, but I rarely see it used in the context of a Transaction. The following approach should always work:
Expand|Select|Wrap|Line Numbers
  1. Dim strSQL As String
  2. Dim wrkDefault As DAO.Workspace
  3. Set wrkDefault = DBEngine.Workspaces(0)
  4.  
  5. wrkDefault.BeginTrans
  6.  
  7. strSQL = "UPDATE [Order Details] SET [UnitPrice] = [UnitPrice] * 1.1"
  8.  
  9. CurrentDb.Execute strSQL, dbFailOnError
  10.  
  11. If vbYes = MsgBox("Commit changes?", vbYesNo) Then
  12.   wrkDefault.CommitTrans
  13. Else
  14.   wrkDefault.Rollback
  15. End If
Apr 26 '11 #2
TheSmileyCoder
2,322 Recognized Expert Moderator Top Contributor
Hi Adezii and thank you for your prompt reply. I did read it earlier today, but was hoping someone else had more to offer. As I said in the post, I did get the transaction to work using currentDB.Execu te strSQL. I guess for a long time I have just been used to using Docmd.RunSQL, so I was curious as why I couldn't get that to work, since it actually specifically takes an argument to indicate whether or not it should be considered part of an transaction.

If I get the time, I will try to research if there is a performance difference between Docmd.RunSQL and CurrentDB.Execu te.
Apr 26 '11 #3
ADezii
8,834 Recognized Expert Expert
From the little research that I have done, it appears that CurrentDB.Execu te is significantly faster than DoCmd.RunSQL since it is a Method of the Jet Database Engine, and runs the SQL directly.
Apr 27 '11 #4
NeoPa
32,573 Recognized Expert Moderator MVP
I haven't got much to add I'm afraid Smiley, but I did read the RunSQL action topic in the Help system which included :
Select Yes to include this query in a transaction. Select No if you don't want to use a transaction. The default is Yes. Prior to Access 97, Access always included the query in a transaction when you ran this action by starting with a BeginTrans method, executing the SQL statement, and then concluding with a CommitTrans method. If you select No for this argument, the query may run faster.

From this I conclude that it probably aught to work exactly as you have used it, but for some reason doesn't :-S

As for which works faster, I would expect the requirement to handle transactions to make a significant difference (whichever method is employed), but I'd be surprised if the two methods differed noticeably in performance outside of that. I say this in the full confidence that my expectations are of little importance, as you will determine the truth of the matter with your testing very shortly :-)
Apr 27 '11 #5

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

Similar topics

0
8247
by: Jim | last post by:
I am using Access 97 on a PC running Windows NT 4.0 SP6a. I have some code (shown below) intended to add a set of records to one table (tblGradeProps) when a new record is created in another (tblGrades) The oddity is that when the procedure Detail_Click is called from the procedure cmbMktSect_Exit, the RunSQL statement doesn't add the required records but it does so when invoked by the Detail_Click event!
4
10191
by: Rotsj | last post by:
Hi, i try to execute an update query from within a form, but i get the message: run time error '3144'. Syntax error on the update statement when i try something like this: DoCmd.RunSQL "UPDATE tblKlant " & _ "SET tblKlant.Bedrag = tblKlant.Bedrag + 10.96" & _ " WHERE tblKlant. = forms!!"
0
1943
by: Andy | last post by:
Hello, I am running an sql statement that INSERTS INTO a table. If I run the query using docmd.runSQL, it works fine - new records are added to the table and duplicate records are disregared ( I use DoCmd.SetWarnings False so the users don't see the warning about duplicate records). If I run the same query using this: rs.Open qryPolePosition1, CurrentProject.Connection, adOpenKeyset,
3
3468
by: Pathfinder | last post by:
Hi All I am trying to run the below but I receive the following error "runsql action requires an argument consisting of an SQL statment" Dim MySQL$ MySQL$ = "Select * from mytablename" DoCmd.RunSQL MySQL$ Any reason for that
7
4297
by: Richard Hollenbeck | last post by:
Help! I don't know why this isn't working: Private Sub Combo9_Change() Dim UsersCourseSelection As String UsersCourseSelection = Me("Combo9").Value Combo13.Visible = True 'the following SQL thing is all on one line in the actual code.
8
11241
by: RC | last post by:
In my Access 2002 form, I have a combo box and on the AfterUpdate event I use DoCmd.RunSQL ("UPDATE .... to update records in a table. When it starts to run I get a message "You are about to update 3 row(s)." Is there a way to prevent the message from popping up?
7
5097
by: Jimmer | last post by:
What's better/ faster/ more efficient. Using Docmd.RunSql or Execute to run sql? When is one better than the other or inappropriate to use? Thanks. jim
2
5707
by: ben | last post by:
I have the following code in a VBA module: DoCmd.RunSql "Update tData Set sd = Log(Strike/Price) where symbol = '" & symbol & "'" This statement worked fine, and was using the built in math Log function. In a separate module, I added the following function:
0
1412
by: dstyles7 | last post by:
there are two list boxes in a form i have a command populate button that takes the values from the list box and inserts the primary key value from the selected list box into a access table. The table populates correctly it shows a message box "You are about to append 1 row(s). Once you click yes, you can't undo command to reverse the changes Are you sure you want to append the selected rows "YES OR NO" The cod behid the populate...
1
3114
MitchR
by: MitchR | last post by:
Hello Folks; I have run myself into a hole I cannot get of and need some assistance. I have a Form "Frm_ATandT_Activation_Center" that has a sub form "Frm_ATandT_Activation". Frm_ATandT_Activation_Center is standard in Form View with no Master or Child links to the Sub form. this allows me to show available SIM ID"S in inventory for activation. The Subform diplays as a datasheet that has a Query as the control source. So when the user opens...
0
9618
marktang
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10260
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, 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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10101
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10038
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
8933
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7456
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6712
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5482
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2850
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.