VBA: Querying Access with Excel. Why so slow?

后端 未结 10 812
情话喂你
情话喂你 2021-01-18 03:24

I found this code online to query Access and input the data into excel (2003), but it is much slower than it should be:

Sub DataPull(SQLQuery, CellPaste)
Dim         


        
10条回答
  •  情书的邮戳
    2021-01-18 04:08

    The problem 9 times out of 10 is to do with the Cursor Type/Location you are using.

    Using dynamic cursors over network connections can slow down the retrieval of data, even if the query executed very fast.

    IF you want to get large amounts of data very quickly, you'll need to use CursorLocation = adUseClient on your connection. This mean's you'll only have a static local cursor, so you won't get live updated from other users.

    However - if you are only reading data, you'll save ADO going back to the DB for each individual record to check for changes.

    I recently changed this as I had a simple loop, populating a list item, and each loop was taking around 0.3s. Not to slow, but even on 1,000 records thats 30 seconds! Changing only the cursor location let the entire process complete in under 1 second.

提交回复
热议问题