Share via

Copying data from an array to an Access table

Anonymous
2012-12-19T17:24:49+00:00

HansV pointed me to the GetRows method of the Recordset object: http://msdn.microsoft.com/en-us/library/office/ff194427.aspx for copying multiple rows of data from an Access table to an array.

After I edit the data in the array (which I assume is much faster than doing so in the Recordset), I want to write it back to the table.  What I don't know how to do is:

  1. How do I get the edited array data back into the Recordset?
  2. Is there a more efficient way to write the edited data from the Recordset back to the table, other than iterating through each record in the Recordset and using the Update method of the Recordset object?

Thanks in advance for any assistance.

Microsoft 365 and Office | Access | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

4 answers

Sort by: Most helpful
  1. Anonymous
    2012-12-24T20:54:48+00:00

    Yes, I am aware of the Query Designer, and converting double quotes within a string to single quotes.  In fact, I always use Query Designer when first building a query.

    Thanks for your feedback.

    Was this answer helpful?

    0 comments No comments
  2. OssieMac 48,001 Reputation points Volunteer Moderator
    2012-12-24T20:41:01+00:00

    Did you know that to get the syntax correct for an SQL string in VBA that you can use the Query design feature and design the query in the matrix. When the query is working correctly, while in Query Design Mode,  you can select View -> SQL View and copy the syntax. You might need to convert double quotes within the string to single quotes and then just enclose the entire string in double quotes to assing to a string variable.

    You can also just save the designed query and then just run it from within the VBA.

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2012-12-24T19:33:21+00:00

    I don't believe that there is a more efficient method than looping to load the array into a table.

    I doubt the accuracy of your assumption of loading the data into an array and then manipulating is faster. If it is, then only in theory and I doubt that you will be able to notice the difference in practice.

     

    SQL queries are very fast. IMHO I think that you would be better to post a new question, including the code you are using to manipulate the data in the array, and ask "Can someone please provide example code to do this without loading into an array and then back to a table"?

    Thanks for your feedback.  My assumption was based solely on my experience using arrays in Excel, which are extremely fast versus reading/writing to individual spreadsheet cells.

    I find it interesting that Microsoft created the GetRows method in Access for copying multiple rows of data from a table to an array, but did not create a corresponding "PutRows" method for doing the reverse.

    From an Access perspective, it would appear that manipulating a RecordSet or using SQL UPDATE queries is, in fact, the fastest way to manipulate data in a table.

    Was this answer helpful?

    0 comments No comments
  4. OssieMac 48,001 Reputation points Volunteer Moderator
    2012-12-23T20:57:45+00:00

      After I edit the data in the array (which I assume is much faster than doing so in the Recordset), I want to write it back to the table.  What I don't know how to do is:

    1. How do I get the edited array data back into the Recordset?
    2. Is there a more efficient way to write the edited data from the Recordset back to the table, other than iterating through each record in the Recordset and using the Update method of the Recordset object?

               

    I don't believe that there is a more efficient method than looping to load the array into a table.

    I doubt the accuracy of your assumption of loading the data into an array and then manipulating is faster. If it is, then only in theory and I doubt that you will be able to notice the difference in practice.

    SQL queries are very fast. IMHO I think that you would be better to post a new question, including the code you are using to manipulate the data in the array, and ask "Can someone please provide example code to do this without loading into an array and then back to a table"?

    Was this answer helpful?

    0 comments No comments