Retrieve data from recordset into ListObject

Stevenn

Active Member
Joined
Feb 8, 2012
Messages
259
What is the best way to print data from a recordset into a ListObject without first deleting the already existing ListObject and converting the new range into a ListObject. I want to avoid this way to do it because all my formulas in other sheets will be result in errors if the already existing ListObject doesn't exist while I delete it and create a new one with the same name. Could it somehow be possible to tell the formulas in the other sheets not to react to a non-existing named ListObject until I've created the new ListObject?
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Hi Steven

1st thing is to clear the DataBodyRange. Then you can drop your recordset straight into the table.
Code:
    With Sheet1.ListObjects("Table1")
        If Not .DataBodyRange Is Nothing Then
            .DataBodyRange.Delete
        End If
    End With

And then all you have to do is drop the recordset; so if your table DataBodyRange starts in A2:
Code:
Call Sheet1.Range("A2").CopyFromRecordset(recData)
 
Upvote 0
Hi Steven

1st thing is to clear the DataBodyRange. Then you can drop your recordset straight into the table.
Code:
    With Sheet1.ListObjects("Table1")
        If Not .DataBodyRange Is Nothing Then
            .DataBodyRange.Delete
        End If
    End With

And then all you have to do is drop the recordset; so if your table DataBodyRange starts in A2:
Code:
Call Sheet1.Range("A2").CopyFromRecordset(recData)

It's a good solution, but what if I want two columns right next to the other columns to contain formulas?
 
Upvote 0
This do not copy recordset to listobject.
It works if A2 is the first cell in the listobject.
But if I move the listobject on the sheet , the code will not work.
Is there a way to actually copy rs to listobject?

My workaround..
Code:
Set rng = Range(tbl.Range.Cells(1).Address).Offset(1, 0) 
rng.CopyFromRecordset rs
Hm.. ok this is about Access database recordset. :eek:
 
Upvote 0

Forum statistics

Threads
1,214,520
Messages
6,120,017
Members
448,936
Latest member
almerpogi

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