I found this code on the Internet for requesting access and entering data in Excel (2003), but it is much slower than it should be:
Sub DataPull(SQLQuery, CellPaste)
Dim Con As New ADODB.Connection
Dim RST As New ADODB.Recordset
Dim DBlocation As String, DBName As String
Dim ContractingQuery As String
If SQLQuery = "" Then
Else
DBName = Range("DBName")
If Right(DBName, 4) <> ".mdb" Then DBName = DBName + ".mdb"
DBlocation = ActiveWorkbook.Path
If Right(DBlocation, 1) <> "\" Then DBlocation = DBlocation + "\"
Con.ConnectionString = DBlocation + DBName
Con.Provider = "Microsoft.Jet.OLEDB.4.0"
Con.Open
Set RST = Con.Execute(SQLQuery)
Range(CellPaste).CopyFromRecordset RST
Con.Close
End If
End Sub
The problem is that this code takes a very long time. If I open Access and just run the request, it takes about 1/10 of the time. Is there any way to speed this up? Or for some reason it can take so long? All my queries are simple select queries with simple where statements and no joins. Even a request select * from [test]takes much longer than necessary.
UPDATE: I must indicate that the line
Range(CellPaste).CopyFromRecordset RST
was the one that took a long time.
source
share