Results 1 to 5 of 5
  1. #1
    usertest is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Oct 2023
    Posts
    35

    Exclamation SQL to Access table takes a lot of time to load data

    Hello,
    I have a SQL table which has 8000 records.
    I am writing a vba code to fetch the whole table into a local access table
    I cant link the table as its not allowed from the admin side.
    The only way I see is using a record set and add row by row using .AddNew

    Below is the code.
    It is taking 8 mins to copy the data.
    Is there any other way I can make it quicker?

    Dim r As New ADODB.Recordset
    Dim r1 As New ADODB.Recordset
    Dim DC As New DataConnection
    Dim strSQL As String
    Debug.Print "autostart" & Now



    CurrentDb.Execute "DELETE * FROM Accesstable;"




    strSQL = "SELECT * FROM SQL Table ;"
    r.Open strSQL, DC.ConnectionName, adOpenKeyset, adLockOptimistic


    strSQL = "SELECT * FROM Accesstable"
    r1.Open strSQL, CurrentProject.Connection, adOpenKeyset, adLockOptimistic


    Do While r.EOF = False


    r1.AddNew
    r1("Col1") = r("Col1")
    r1("Col2") = r("Col2")
    r1("Col3") = r("Col3")
    r1.Update
    r.MoveNext
    Loop
    r.Close
    r1.Close
    Set r = Nothing
    Set r1 = Nothing




    Debug.Print "autoend" & Now
    End Sub


    Please, any help would be appreciated

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    You mean you have a SQLServer table? SQL is not a database, it is a language.

    What do you mean by you can't link the table? You are linking when you establish a connection. How and where is DC.ConnectionName set? VBA can set links to SQLServer tables.

    You could try setting up a Pass-Through query and use that as source for an INSERT SELECT action. Review https://kb.blackbaud.com/knowledgebase/Article/52445 and https://stackoverflow.com/questions/...hrough-queries

    With a Pass-Through query you could review data (not edit) without having to save to a local table and use as source in Access queries. However, I don't know if this will allow faster performance when querying the dataset.

    Note for future: Please post code between CODE tags to retain indentation and readability.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    usertest is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Oct 2023
    Posts
    35
    Hi,
    I created the pass-through query as you mentioned.
    Thanks for that.
    Quick question: Can I also compare records from Pass through query and access tables, and if the ID's do not match, create a new access table and add those records?
    Is that possible?

    Thanks!

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Work with the pass-through as you would any table except for editing. So try a Find Unmatched query. Access has a query build wizard for that. But you might not need that for UPDATE/INSERT issue - check out the UPSERT method. Review https://stackoverflow.com/questions/...crosoft-access
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    Join Date
    Jun 2010
    Location
    Belgium
    Posts
    1,044
    Tip: when working with SQL data (SQL server, MySQL, Oracle, ...) always try to avoid RBAR (Row By Agonizing Row) operations. More info https://www.red-gate.com/simple-talk...agonizing-row/

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Table takes over data from form
    By Akchayan in forum Forms
    Replies: 2
    Last Post: 11-14-2022, 10:20 AM
  2. Replies: 2
    Last Post: 10-03-2018, 06:04 AM
  3. Replies: 10
    Last Post: 04-17-2012, 10:29 AM
  4. Report data load time
    By GraemeG in forum Reports
    Replies: 0
    Last Post: 06-05-2011, 05:52 AM
  5. Replies: 9
    Last Post: 10-09-2009, 08:15 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums