Print Page | Close Window

Sending records to Excel using CopyFromRrecordSet

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Report Control
Forum Description: Topics Related to Codejock Report Control
URL: http://forum.codejock.com/forum_posts.asp?TID=17287
Printed Date: 15 November 2024 at 1:41pm
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: Sending records to Excel using CopyFromRrecordSet
Posted By: mstuart
Subject: Sending records to Excel using CopyFromRrecordSet
Date Posted: 20 September 2010 at 5:32pm
Hi all,
Is there any chance that using the Excel Range.CopyFromRecordSet ReportRecords would send records of the ReportControl to Excel?
Anyone using this at all? If so, do you have an example VB6 code that shows how?

Regards,
Mark Stuart


-------------
Regards,
Mark Stuart

Product: Xtreme SuitePro (ActiveX) v13.2.1
Platform: WinXP (32bit)/Win7 (64bit)
Language: VB6 (SP6), Magic eDeveloper v9.4, uniPaaS v1.9



Replies:
Posted By: SHAN
Date Posted: 21 September 2010 at 1:13am
HI Mark Stuart,
 
Please Find the Code below as you requested ....!

 ---------------------------------------------------------------------------
Public Sub ReportControlToExcel(Rptcontrol As ReportControl)
      Dim xlObject    As Excel.Application
 
      Dim xlWB        As Excel.Workbook
            
          Set xlObject = New Excel.Application
 
      
          'This Adds a new woorkbook, you could open the workbook from file also
 
          Set xlWB = xlObject.Workbooks.Add
                  
          Clipboard.Clear 'Clear the Clipboard
          'Add Column Headers
             For i = 1 To Rptcontrol.Columns.count
                   xlObject.ActiveSheet.Cells(1, i).Value = _
                        "" & Rptcontrol.Columns.Column(i - 1).Caption
              Next
             
           'Select All Records
                        For i = 0 To Rptcontrol.Rows.count - 1
                         Rptcontrol.Rows(i).Selected = True
                        Next
             'Copy Records to ClipBoard
                      Rptcontrol.Copy
              With xlObject.ActiveWorkbook.ActiveSheet
 
              .Range("A2").Select 'Select Cell A2 (will paste from here, to different cells)
              .Paste              'Paste clipboard contents
              End With
              'Clear Selected Records from Selection
              Rptcontrol.SelectedRows.DeleteAll
           Clipboard.Clear
                      'Format excel Columns
             For i = 1 To Rptcontrol.Columns.count
            xlObject.ActiveSheet.Columns(i).AutoFit
            xlObject.ActiveSheet.Columns(i).HorizontalAlignment = xlCenter
              Next
              'Format Excel Rows
             xlObject.ActiveSheet.Rows(1).Font.Bold = True
          xlObject.ActiveSheet.Rows(1).Interior.Color = &HFFC0C0
         xlObject.ActiveSheet.Rows(2).Select
         'Freeze the First Row
         xlObject.ActiveWindow.FreezePanes = True
        
          ' This makes Excel visible
          xlObject.Visible = True

End Sub
 
 
-----------------------------------------------------------------------------------
'To call the Method Use
 
call ReportControlToExcel(Reportcontrol1)
--------------------------------------------------------------------------------------
 


-------------
Product: Xtreme SuitePro (ActiveX) version 15.0.2
Platform: Windows 7 Professional
Language: Visual Basic 6.0


Posted By: mstuart
Date Posted: 21 September 2010 at 5:13pm
Hi Shan,
I was mostly interested in the CopyFromRecordSet method.
I've used this with the ADODB.Connection and ADODB.RecordSet objects, and was hoping to just reference the ReportRecords collection/object to the method.

Reason being: 
1) there may be a lot of records that have to be loaded, Using the clipboard with a large record set, may crash the program.
2) some columns may be hidden by the user, removing a column from the ReportControl during runtime, and therefore the program has to consider not to send the hidden column(s) to Excel.
3) Also, I'm using the 1st column as a checkbox. This allows the user to check which records to work with to send to Excel.

Regards,
Mark Stuart


-------------
Regards,
Mark Stuart

Product: Xtreme SuitePro (ActiveX) v13.2.1
Platform: WinXP (32bit)/Win7 (64bit)
Language: VB6 (SP6), Magic eDeveloper v9.4, uniPaaS v1.9



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.04 - http://www.webwizforums.com
Copyright ©2001-2021 Web Wiz Ltd. - https://www.webwiz.net