|
-
May 16th, 2012, 04:56 AM
#1
Thread Starter
Junior Member
Problem while copying data from recordset to excel
I am using below code
cnt.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & "C:\work\User Audit Tool\AuditReports\;" & _
"Extended Properties=""Text;HDR=No;"""
rs.Open "Select * from AuditReport.csv", cnt, adOpenStatic, adLockReadOnly, adCmdText
Set objXLApp = CreateObject("Excel.Application")
Set xlWb = objXLApp.Workbooks.Add
Set xlWs = xlWb.Worksheets("Sheet1")
objXLApp.Visible = True
i = 1
With rs
.MoveFirst
Do Until .EOF
xlWs.Cells(i, 1).CopyFromRecordset rs, 1
i = i + 1
'objWS.Range(objWS.Cells(1, 1), objWS.Cells(1, rs.Fields.Count)).Font.Bold = True
If i > 10 And i < 21 Then
Set xlWs = objXLApp.Worksheets.Add
'objWS.Range(xlWs.Cells(i - 11, 1)).CopyFromRecordset rs
xlWs.Cells(i - 10, 1).CopyFromRecordset rs
End If
If i > 20 Then
Set xlWs = objXLApp.Worksheets.Add
xlWs.Cells(i - 20, 1).CopyFromRecordset rs
End If
.MoveNext
Loop
End With
But when i try to debug using F8 ,the debugger only moves between two statements below .MoveNext statement
ie.
Do Until .EOF
xlWs.Cells(i, 1).CopyFromRecordset rs, 1
But somehow it copies first 10 records to sheet 1 and the rest of them to sheet 2 ...don't know how can it add sheet without the cursor going into the sheet adding statements.
Please help!!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|