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 "TestQueryR un" 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?
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 "TestQueryR un" 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?
Code:
Public Function TestQueryRun() As Boolean
On Error GoTo ERRORHANDLER
Dim StartDate As Date
Dim End_Date As Date
Dim queryName As String
End_Date = #9/9/2014#
StartDate = End_Date
queryName = "Append_History_Query"
' I tried this method to see if it would improve performance
' It resulted
' DoCmd.SetParameter "Start_Date", StartDate
' DoCmd.SetParameter "End_Date", End_Date
'
' DoCmd.OpenQuery "Append_History_Query"
'
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Set db = CurrentDb
Set qdf = db.QueryDefs(queryName)
qdf.Parameters("Start_Date") = StartDate
qdf.Parameters("End_Date") = End_Date
Debug.Print Now()
qdf.Execute
Debug.Print Now()
TestQueryRun = True
EXITHANDLER:
Exit Function
ERRORHANDLER:
TestQueryRun = False
GoTo EXITHANDLER
End Function
Comment