CopyFromRecordset

Salamander

Board Regular
Joined
Jul 30, 2009
Messages
64
Hi guys,

Wasn't sure whether to put this Excel or Access forum but given that it's primarily in Access... here goes =D

I have the following code which I thought was very simple.

Code:
Rem ** Open RS
    rs.Open theQuery, cnn, adOpenDynamic, adLockOptimistic, adCmdTable
 
    If rs.EOF = True Then
        GoTo 8
    End If
    
Rem ** Export to a new Excel
    Dim myXL As Excel.Application: Set myXL = New Excel.Application
    Dim wb As Workbook: Set wb = myXL.Workbooks.Add
    
    With wb.Sheets(1).Range("a1")
        For i = 0 To rs.Fields.Count - 1
            .Offset(, i).Value = rs.Fields(i).Name
        Next i
    End With
    
    'myXL.Visible = True
    
    With wb.Sheets(1)
        .Range("a2").CopyFromRecordset rs
        .Cells.EntireColumn.AutoFit
        .Cells.Rows.Height = 12.75
        .Rows(1).Insert
        With .Range("a1")
            .Value = "Stage 4 Referrals"
            .Font.Bold = True
            .Font.Size = 22
        End With
    End With

However it gets to:

Code:
.Range("a2").CopyFromRecordset rs

and then just stops, it populates the spreadsheet, returns no error but stops running.

I'm not dealing with massive amounts of data here (currently only 145 rows..!) so at a bit of a loss as to where to go form here...

Any help would, as ever, be greatly appreciated! =D


Cheers,

S.
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Hi guys,

Sorry about that - sorted it myself.

The function was called within another sub which had an On Error in place, have found where the error was and fixed it.... d'oh.

Cheers anyway guys =D
 
Upvote 0
Hi guys,

Sorry about that - sorted it myself.

The function was called within another sub which had an On Error in place, have found where the error was and fixed it.... d'oh.

Cheers anyway guys =D

Cascading error handling can be a real pain :mad:

Denis
 
Upvote 0

Forum statistics

Threads
1,215,767
Messages
6,126,778
Members
449,336
Latest member
p17tootie

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