Hi Everyone,
Can someone please help me. I am trying to create an excel file through Access and i get run-time error 430 Class doesnt support Automation. I have attached my code:
THANKS!!!!!!!!!!
Private Sub cmdGetReport_Click()
Dim adoConn As New ADODB.Connection
Dim adoRec As New ADODB.Recordset
Dim xlApp As Excel.Application
Dim strsql As String
Dim xlWB As Excel.Workbook
Dim strfilename As String
Dim i As Long
Set xlApp = New Excel.Application
adoConn.CommandTimeout = 0
adoConn.Open "DSN=mays"
strsql = "select * from dw.maysoon_proc_test"
adoRec.Open strsql, adoConn
xlApp.Workbooks.Add
Set xlWB = xlApp.ActiveWorkbook
For i = 0 To adoRec.Fields.Count - 1
Cells(1, i + 1).Value = adoRec.Fields(i).Name
Next
xlWB.Sheets(1).Range("A2").CopyFromRecordset adoRec<********ERROR OCCURS HERE************************>
strfilename = "C:\TESTING2.xls"
If Len(Dir(strfilename)) Then
Kill strfilename
End If
'ActiveWorkbook.SaveAs strfilename
adoConn.Close
Can someone please help me. I am trying to create an excel file through Access and i get run-time error 430 Class doesnt support Automation. I have attached my code:
THANKS!!!!!!!!!!
Private Sub cmdGetReport_Click()
Dim adoConn As New ADODB.Connection
Dim adoRec As New ADODB.Recordset
Dim xlApp As Excel.Application
Dim strsql As String
Dim xlWB As Excel.Workbook
Dim strfilename As String
Dim i As Long
Set xlApp = New Excel.Application
adoConn.CommandTimeout = 0
adoConn.Open "DSN=mays"
strsql = "select * from dw.maysoon_proc_test"
adoRec.Open strsql, adoConn
xlApp.Workbooks.Add
Set xlWB = xlApp.ActiveWorkbook
For i = 0 To adoRec.Fields.Count - 1
Cells(1, i + 1).Value = adoRec.Fields(i).Name
Next
xlWB.Sheets(1).Range("A2").CopyFromRecordset adoRec<********ERROR OCCURS HERE************************>
strfilename = "C:\TESTING2.xls"
If Len(Dir(strfilename)) Then
Kill strfilename
End If
'ActiveWorkbook.SaveAs strfilename
adoConn.Close