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
- 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