+ Reply to Thread
Results 1 to 8 of 8

Insert values of array into ACCESS DB

  1. #1
    Registered User
    Join Date
    05-31-2012
    Location
    Dubai, UAE
    MS-Off Ver
    Excel 2010
    Posts
    27

    Question Insert values of array into ACCESS DB

    Hi all,

    I have developed the undermentioned code to insert values into an Access table. The function RtnQryStr just creates the insert string using the values in an array called UniqueArray(i) after splitting them as shown.

    My issue is I have a file with about 200000+ records. And it takes ages for it to execute every value one by one in the QryString.

    Is there any way to insert all these values in one go?
    If there is a way, would QryString be able to hold that large chunk of data strings to insert?

    Please Login or Register  to view this content.
    Please Login or Register  to view this content.

  2. #2
    Registered User
    Join Date
    05-31-2012
    Location
    Dubai, UAE
    MS-Off Ver
    Excel 2010
    Posts
    27

    Re: Insert values of array into ACCESS DB

    In case anyone is wondering, I cannot use recordsets because I am on Win 64 bit, and for some reason ADO is not recognized so I have to access the database using the methods available in Access.Application object.

  3. #3
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Insert values of array into ACCESS DB

    AFAIK Access has no bulk insert facility. To speed things up, check a few things:
    • You are using DAO rather than ADO
    • You are not closing and re-opening the connection for each insert
    • You aren't doing any looping of the worksheet
    • All your excel code is efficient as possible

  4. #4
    Registered User
    Join Date
    05-31-2012
    Location
    Dubai, UAE
    MS-Off Ver
    Excel 2010
    Posts
    27

    Re: Insert values of array into ACCESS DB

    1) I am using the methods available via Access.Application object.
    2) I am not closing and reopening the connections. In fact Access.Application object works on whatever Databases are opened at the time of code execution so I am using
    Please Login or Register  to view this content.
    to open the database I have the table in.
    3) I am not doing any looping of the worksheet.
    4) The only thing that is not efficient is me inserting rows one by one, the reason that i am here.

  5. #5
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Re: Insert values of array into ACCESS DB

    I also have this problem and Kyle has helped me out over this before. But unfortunately as Kyle says there is no way to do it. I was also given good advise that you are better off knowing that each line is being inserted correctly. Sometimes my code can 4-5 mins to insert data into Access. But I use ADO for access as that is what I know best to use at the moment.
    Be fore warned, I regularly post drunk. So don't take offence (too much) to what I say.
    I am the real 'Napster'
    The Grid. A digital frontier. I tried to picture clusters of information as they moved through the computer. What did they look like? Ships? motorcycles? Were the circuits like freeways? I kept dreaming of a world I thought I'd never see. And then, one day...

    If you receive help please give thanks. Click the * in the bottom left hand corner.

    snb's VBA Help Files

  6. #6
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Insert values of array into ACCESS DB

    Then no, Access doesn't support bulk inserts through sql.

    The other solution would be to use the text import wizard and do it that way

  7. #7
    Registered User
    Join Date
    05-31-2012
    Location
    Dubai, UAE
    MS-Off Ver
    Excel 2010
    Posts
    27

    Re: Insert values of array into ACCESS DB

    Is there any way for me to use the ACCESS text import wizard using vba?

  8. #8
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Insert values of array into ACCESS DB

    Probably. I don't have access though. A quick google turned this up

    http://www.ozgrid.com/forum/showthread.php?t=32942

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1