Harry Flashman
Active Member
- Joined
- May 1, 2011
- Messages
- 361
I have a pivot table which is linked to a query in Access. The trouble is it can be very slow updating.
I update this pivot table via VBA. But I think originally I just manually made the connection, while using the macro recorder. And the code I use to refresh the data is a stripped down version of that recorded code.
I have previously written code to fetch data from Access to an Excel worksheet using an ADODB.Connection, and I found by changing certain parameters of the ADODB.Recordset I was able to dramatically speed up the amount of time it took to fetch the data, specifically by changing the CursorType to adOpenForwardOnly and the LockType to adLockReadOnly.
I was hoping there might be some way of changing my code above in a similar way but the recorded code makes no mention of an ADODB.Connection or an ADODB.Recordset and I have thus I don't know how to change the CursorType or LockType.
Can someone give me a few pointers please?
I update this pivot table via VBA. But I think originally I just manually made the connection, while using the macro recorder. And the code I use to refresh the data is a stripped down version of that recorded code.
Code:
Sub SQLQueryWithVBA2()
MySource = "C:\MyDataBase.accdb"
MyCommand = "SELECT * FROM D_Current_Extracts"
With ActiveWorkbook.Connections("DCurrentExtracts").OLEDBConnection ' this is the name of the Pivot Table source data connection
.CommandText = MyCommand
.CommandType = xlCmdSql
.Connection = "OLEDB;Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & MySource
End With
ActiveWorkbook.Connections("DCurrentExtracts").Refresh
End Sub
I have previously written code to fetch data from Access to an Excel worksheet using an ADODB.Connection, and I found by changing certain parameters of the ADODB.Recordset I was able to dramatically speed up the amount of time it took to fetch the data, specifically by changing the CursorType to adOpenForwardOnly and the LockType to adLockReadOnly.
I was hoping there might be some way of changing my code above in a similar way but the recorded code makes no mention of an ADODB.Connection or an ADODB.Recordset and I have thus I don't know how to change the CursorType or LockType.
Can someone give me a few pointers please?