T
tjharlan
Hi All - struggling with the below. Simply trying to paste an Access
recordset into Excel. I am getting the "Class does not support Automation"
error at run-time. Please see all details below.
Your advice or direction would be greatly appreciated. Thank you.
Rgds,
T.J.
ERROR: "Run-time error '430'; Class does not support Automation or does not
support expected interface"
LINE OF CODE TRIGGERING THE ERROR MSG:
xlWs.Cells(2, 1).CopyFromRecordset rs2
XL VERSION - Excel 2003 - SP2
ACCESS VERSION - Access 2003 - SP2
REFERENCES USED:
* Visual Basic for Applications
* Microsoft Access 11.0 Object Library
* OLE Automation
* Microsoft ActiveX Data Objects 2.8 Library
CODE:
Sub fileclean2()
DoCmd.Hourglass (True)
Dim strDir As String
Dim strFile As String
Dim strFindText As String
Dim strReplaceText As String
Dim strContents As String
Dim strStart As String
Dim strFinish As String
Dim XlApp As Object
Dim xlwb As Object
Dim xlWs As Object
Dim rs As New ADODB.Recordset
Dim rs2 As New ADODB.Recordset
Dim strSQL As String
strStart = Now()
Const ForReading = 1
Const ForWriting = 2
'open excel
Set XlApp = CreateObject("Excel.Application")
XlApp.Visible = True
'open worksheet to create report
Set xlwb = XlApp.Workbooks.Add
Set xlWs = xlwb.Worksheets("Sheet1")
rs.ActiveConnection = CurrentProject.Connection
rs2.ActiveConnection = CurrentProject.Connection
strSQL = "select distinct location, analyst from tblABCD"
rs.Open (strSQL)
strSQL = "Select contra from tblABCD where location = '" &
rs.Fields("location") & "' and analyst = '" & rs.Fields("analyst") & "'"
rs2.Open (strSQL)
'add headers to report
fldcount = rs2.Fields.Count
For iCol = 1 To fldcount
xlWs.Cells(1, iCol).Value = rs2.Fields(iCol - 1).Name
xlWs.Cells(1, iCol).Font.Bold = True
Next
xlWs.Cells(2, 1).CopyFromRecordset rs2
strFinish = Now()
MsgBox "Finito! " & strStart & " " & strFinish
DoCmd.Hourglass (False)
End Sub
recordset into Excel. I am getting the "Class does not support Automation"
error at run-time. Please see all details below.
Your advice or direction would be greatly appreciated. Thank you.
Rgds,
T.J.
ERROR: "Run-time error '430'; Class does not support Automation or does not
support expected interface"
LINE OF CODE TRIGGERING THE ERROR MSG:
xlWs.Cells(2, 1).CopyFromRecordset rs2
XL VERSION - Excel 2003 - SP2
ACCESS VERSION - Access 2003 - SP2
REFERENCES USED:
* Visual Basic for Applications
* Microsoft Access 11.0 Object Library
* OLE Automation
* Microsoft ActiveX Data Objects 2.8 Library
CODE:
Sub fileclean2()
DoCmd.Hourglass (True)
Dim strDir As String
Dim strFile As String
Dim strFindText As String
Dim strReplaceText As String
Dim strContents As String
Dim strStart As String
Dim strFinish As String
Dim XlApp As Object
Dim xlwb As Object
Dim xlWs As Object
Dim rs As New ADODB.Recordset
Dim rs2 As New ADODB.Recordset
Dim strSQL As String
strStart = Now()
Const ForReading = 1
Const ForWriting = 2
'open excel
Set XlApp = CreateObject("Excel.Application")
XlApp.Visible = True
'open worksheet to create report
Set xlwb = XlApp.Workbooks.Add
Set xlWs = xlwb.Worksheets("Sheet1")
rs.ActiveConnection = CurrentProject.Connection
rs2.ActiveConnection = CurrentProject.Connection
strSQL = "select distinct location, analyst from tblABCD"
rs.Open (strSQL)
strSQL = "Select contra from tblABCD where location = '" &
rs.Fields("location") & "' and analyst = '" & rs.Fields("analyst") & "'"
rs2.Open (strSQL)
'add headers to report
fldcount = rs2.Fields.Count
For iCol = 1 To fldcount
xlWs.Cells(1, iCol).Value = rs2.Fields(iCol - 1).Name
xlWs.Cells(1, iCol).Font.Bold = True
Next
xlWs.Cells(2, 1).CopyFromRecordset rs2
strFinish = Now()
MsgBox "Finito! " & strStart & " " & strFinish
DoCmd.Hourglass (False)
End Sub