473,474 Members | 1,836 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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

16 New Member
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 3074
twinnyfo
3,653 Recognized Expert Moderator Specialist
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
BrianRiggs
1 New Member
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 Recognized Expert Moderator Expert
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 New Member
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 Recognized Expert Moderator Expert
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 New Member
>>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 Recognized Expert Moderator Expert
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...
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,...
1
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
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,...
1
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...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.