Results 1 to 7 of 7

Thread: Excel Automation Error

Threaded View

  1. #1

    Thread Starter
    Frenzied Member SeanK's Avatar
    Join Date
    May 2002
    Location
    Boston MA
    Posts
    1,160

    Excel Automation Error

    I'm getting an Automation Error when attempting to use CopyFromRecordset to dump the contents of a recordset created in VB6 to Excel. Here is my code
    VB Code:
    1. Dim oXlApp As Object, oXLWb As Object, oXLWs As Object
    2.  
    3. Dim vRecArray As Variant
    4.     Dim lRecCount As Long
    5.     Dim iFldCount As Integer, iCol As Integer, iRow As Integer
    6.      
    7.     'Create an instance of Excel and add a workbook
    8.     Set oXlApp = CreateObject("Excel.Application")
    9.     Set oXLWb = oXlApp.Workbooks.Add
    10.     Set oXLWs = oXLWb.Worksheets("Sheet1")
    11.    
    12.     'Display Excel and give user control of Excel's lifetime
    13.     oXlApp.Visible = True
    14.     oXlApp.UserControl = True
    15.    
    16.     'Copy field names to the first row of the worksheet
    17.     iFldCount = adoRS.Fields.Count
    18.    
    19.     For iCol = 1 To iFldCount
    20.         oXLWs.Cells(1, iCol).Value = adoRS.Fields(iCol - 1).Name
    21.     Next iCol
    22.  
    23.    [HL="#FFFF80"]oXLWs.Cells(2, 1).CopyFromRecordset adoRS[/HL]
    The error occurs on the highlighted line, and here is the error.
    Attached Images Attached Images  
    Beantown Boy
    Please use [highlight=vb]your code goes in here[/highlight] tags when posting code.
    When you have received an answer to your question, please mark it as resolved using the Thread Tools menu.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width