Fill Excel table with Access data

Stevenn

Active Member
Joined
Feb 8, 2012
Messages
259
How can I fill an Excel table with data from my Access database?

I know how to connect to the database and defining my recordset, but don't know how to handle the tables.

Can I do something like ListObjects("Table1").Cells.objRecordset.GetRows()?
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
To get the fields you need to loop through their names. Then use CopyFromRecordset to "paste" the recordset.

i.e.

Code:
For i = 0 To objRecordset.RecordCount - 1

    Cells(1, i + 1).Value = objRecordset.Fields(i).Name

Next i

Range("A2").CopyFromRecordset objRecordset

Hope it helps
 
Upvote 0
To get the fields you need to loop through their names. Then use CopyFromRecordset to "paste" the recordset.

i.e.

Code:
For i = 0 To objRecordset.RecordCount - 1
 
    Cells(1, i + 1).Value = objRecordset.Fields(i).Name
 
Next i
 
Range("A2").CopyFromRecordset objRecordset

Hope it helps

Thanks for the answer. Sorry if my post was not understandable. I know how to insert data in my sheet, but i want to insert in a specific table under the right column names :-)
 
Upvote 0
You should update your Select query on the basis of Excel template and fix their column names and change your desitionation cell ( Range("XX")).. don't populate the Fields name again.

Query 1.

Range("A2").CopyFromRecordset objRecordset

Query 2
Range("AA2").CopyFromRecordset objRecordset

Query 3
Range("BA2").CopyFromRecordset objRecordset

And if you really don't want the update the query then use a Match function to check for for the Filelds name in a column header in Excel and paste the data of that column below the column name(through a loop for each item in that column or some method would be there to paste only one column).
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,217
Members
452,619
Latest member
Shiv1198

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top