473,385 Members | 2,180 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,385 software developers and data experts.

Append Query runs slower in VBA than if I click on it in Access 2007 interface. Why?

16
My query, "Append_History_Query," appends Oracle data to a local Access table. It has 2 date parameters. It has one join from one Oracle table to another. It is appending approximately 20,000 records, with about 20 fields.

The originating tables are on the Oracle server. There is a primary key - foreign key to the linked Oracle tables it is linking to. The local table it is appending to is empty and is not indexed.

When I run my "Append_History_Query" from the Access interface by double clicking the query, it takes just over a minute.

However, when I run it using the "TestQueryRun" code below, it takes 4-5 minutes.

I’ve tried to append it to a local table that is not indexed and indexed, but the results are the same for both methods.

Why does it take 4 times longer within VBA than if I click on it within the interface?

Expand|Select|Wrap|Line Numbers
  1.  
  2. Public Function TestQueryRun() As Boolean
  3.  
  4.    On Error GoTo ERRORHANDLER
  5.    Dim StartDate As Date
  6.    Dim End_Date As Date
  7.    Dim queryName As String
  8.  
  9.     End_Date = #9/9/2014#
  10.     StartDate = End_Date
  11.     queryName = "Append_History_Query"
  12.  
  13. ' I tried this method to see if it would improve performance
  14. ' It resulted 
  15.  
  16. '    DoCmd.SetParameter "Start_Date", StartDate
  17. '    DoCmd.SetParameter "End_Date", End_Date
  18. '
  19. '    DoCmd.OpenQuery "Append_History_Query"
  20. '
  21.  
  22. Dim db As DAO.Database
  23. Dim qdf As DAO.QueryDef
  24.  
  25. Set db = CurrentDb
  26. Set qdf = db.QueryDefs(queryName)
  27. qdf.Parameters("Start_Date") = StartDate
  28. qdf.Parameters("End_Date") = End_Date
  29. Debug.Print Now()
  30. qdf.Execute
  31. Debug.Print Now()
  32.  
  33.     TestQueryRun = True
  34.  
  35. EXITHANDLER:
  36.     Exit Function
  37.  
  38. ERRORHANDLER:
  39.  
  40.     TestQueryRun = False
  41.  
  42.     GoTo EXITHANDLER
  43. End Function
  44.  
  45.  
  46.  
Sep 11 '14 #1
7 3071
twinnyfo
3,653 Expert Mod 2GB
drumahh,

Very strange. I usually find just the opposite, that my queries run more quickly from within VBA. I don't think you're doing anything wrong. You're just getting unexpected results. Perhaps some others may have insight as to the delays.
Sep 11 '14 #2
Since you have no control on the JET/ACE engine query plan and since Oracle must do all the calculation before sending data back bypass MS Access query planning by using a Pass-Thru OBDC query which will use native Oracle SQL.

The append query in MS Access will reference your new Pass-Thru query. The SQL of the APPEND query will be something like: INSERT INTO localtable SELECT * FROM passthruquery;
Sep 12 '14 #3
zmbd
5,501 Expert Mod 4TB
drumahh:
We need to see the SQL behind the query.
We need to see the connection string or have an idea as to how you are connecting to the backend

Also... not fair to compare opening the immediate i/o
execute your query
and the push the call back to the immediate i/o
Expand|Select|Wrap|Line Numbers
  1.  Debug.Print Now()
  2. qdf.Execute
  3. Debug.Print Now()
You are comparing apples to oranges.
Access isn't a multithreaded processor. It starts one thing (immediate's gui - i/o), starts your query, then comes back to the gui... that takes a bit if time.
Sep 20 '14 #4
drumahh
16
I used Mr. Riggs solution by using a Pass-Through query, and then an Append query referencing the Pass-Through query. The time for the execution is now about 15 seconds. It was 5 minutes using VBA and just over a minute clicking the interface. So, I will be using a Pass-Through queries as much as possible, and bypassing the Access Jet layer when I can. It is truly the best solution

Regarding the SQL and ODBC, here is the neutered SQL and ODBC connection

Expand|Select|Wrap|Line Numbers
  1. PARAMETERS Start_Date DateTime, 
  2. End_Date DateTime;
  3.  
  4. INSERT INTO local_table1 
  5. (
  6. field1, 
  7. field2, 
  8. field3, 
  9. ...
  10. field60
  11. )
  12.  
  13. SELECT Oracle_table_1.OracleField1 AS field1, 
  14. "" AS field2, 
  15. Oracle_table_1.OracleField3 AS field3, 
  16. Oracle_table_2.OracleField4 AS field4, 
  17. Oracle_table_1.OracleField5 AS field5, 
  18. Oracle_table_1.OracleField6 AS field6, 
  19. -1 AS field7, 
  20. Oracle_table_1.OracleField8 AS field8, 
  21. Oracle_table_2.OracleField9 AS field9, 
  22. Oracle_table_1.OracleField10 AS field10, 
  23. "" AS AS field11, 
  24. ...
  25.  
  26. Oracle_table_1.OracleField50
  27.  
  28. FROM Oracle_table_1 LEFT JOIN 
  29. Oracle_table_2 ON Oracle_table_1.field7 = Oracle_table_2.field7
  30.  
  31. WHERE (((Oracle_table_1.Field_DT) Between [Start_Date] And [End_Date]));
  32.  
  33. --------------
  34. Connection String:
  35.  
  36. ODBC;DRIVER={Oracle in OracleClientHome};SERVER=OracleServerName;DBQ=OracleServerName;DBA=W;APA=T;EXC=F;XSM=Default;FEN=T;QTO=T;FRC=10;FDL=10;LOB=T;RST=T;BTD=F;BNF=F;BAM=IfAllSuccessful;NUM=NLS;DPM=F;MTS=T;MDI=Me;CSR=F;FWC=F;FBS=60000;TLO=O;MLD=0;ODA=F;
  37.  
  38.  
Regarding “Also... not fair to compare opening the immediate i/o execute your query and the push the call back to the immediate i/o”

I put the Debug.Print statements before and after the problem areas “after” the issue was discovered so I could get a repeatable quantitative time estimate for the execution of the query. I’m assuming the Debug.Print does not take more than a second or so to execute.

I am abandoning the “Why is Access behaving this way” for others to ponder. I now have an acceptable solution using Pass-Through queries.

Thanks!
Sep 22 '14 #5
zmbd
5,501 Expert Mod 4TB
I've reset the answer.
Although the pass thru query maybe the workaround... it does not answer the question asked and therefor cannot be selected as best answer.

Wither or not one starts the query from a stored procedure or from VBA, we do not have any control over how the database engine does or does not optimize performance. Furthermore, there is no documentation that indcates that any such difference exsists between executing a stored query either via the GUI or from VBA; hence why I asked for the stored query's SQL in hopes that somehting there would help explain.
Sep 22 '14 #6
drumahh
16
>>why I asked for the stored query's SQL in hopes that somehting there would help explain.

So does the 1 join SQL statement or the ODBC connection explain anything?
Sep 22 '14 #7
zmbd
5,501 Expert Mod 4TB
it's most likely with the qrydef object and the execute method - however, that's kind of captain obvious there (°®°)
my suspicion here is that the query is being flagged for recompile at runtime and something is causing that to be deoptimized.

Normally I build my SQL in the module and then pass that string to the database.execute method; thus, I don't pass parameters to the qrydef object.

Anyway the speed being slower is counter to what one would expect (QueryDef Object Acc2007)

I don't have an Oracle server to play with that has a table anything close to what your SQL indicates; thus, I am not able to re-create the issue.
Sep 22 '14 #8

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

Similar topics

1
by: djbigpond | last post by:
I have a query I developed and optimised as well as possible before converting to a view. When running in query analyser the query runs in 15 to 18 seconds - which is acceptable. When...
1
by: David Barger | last post by:
Greetings, It appears that an Append Query I run in Access XP is randomly failing to append a field. I have payroll data being entered into a payroll database. This data is exported daily to...
0
by: ingrammx | last post by:
Does anyone know how to append data from a MS Access query to a .txt file. I have a process to import data and check for errors. I would like to report the errors to a text file after every import...
1
by: myipmike | last post by:
Hi there, I have an app that produces labels and which runs fine under Access 2000, 2002 and 2003. The compiled 2002 .mde version runs fine under Access 2007 but only sometimes ! i.e. under XP...
0
by: Accessed | last post by:
This Access 2007 interface is weird!! I have two query results I want to view side by side, but there seems to be no way to tile them either horizontally or vertically! Any one discover the...
3
by: Gerhard | last post by:
Hi I have a combobox on a form which gets it's Row Source from a table. I then use an Append Query to save the selected data in the combobox to a file. Everything works fine. The Combobox's...
0
by: dbdream | last post by:
Hi, I'm having major performance issues in testing with Access 2007 after Access 97 applications are converted (.mdb) format. Loading of forms or reports are 2-3 times slower in Access 2007 than in...
6
by: slenish | last post by:
Hello, First just want to say im going to try and explain this the best I can and hope i dont confuse people :) What I have is a form to delete a record. Now what I have set the form up to...
0
by: Ulf Malmros | last post by:
Hi I have an application that is developed in ACCESS 2007 but runs in the ACCESS 2007 shell (Access 2007 runtime). When I run it in the development environment it runs without any errors but...
1
by: JD79 | last post by:
I have an access 2007 database (on an XP machine) that extracts a large set of data from an Oracle db using ODBC. The data extraction is done with a dynamic passthru query that is then called in a...
1
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...
0
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...
0
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...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
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...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.