Dear Forum members:
I'm having some trouble with Access to Excel automation. This site has been extremely helpful. I've searched for many a solution on this site and found many answers. Now I need to ask a specific question. I'll be as brief and to the point as possible.
Objective: Create a monthly Excel spreadsheet that takes data from Access and makes a new tab for every grouping (Pyramid) in the recordset. Then I wish to copy each Pyramid's records into the corresponding tab in Excel. I am working in Access 2000 and Excel 2000. I prefer DAO because I haven't learned ADO yet.
Below is the code I've written so far. Please see the red code and my bolded comments. I took the CopyFromRecordset method right out of Access help. But it's not working??? Perhaps I'm not setting the range right? Thanks in advance for your assistance.
Set rngXL = objXL.ActiveSheet.Range("A1"
rngXL.CopyFromRecordset rsXLData
the code in red here is where I am hanging up I get
error 430 Class does not support Automation or does not support expected interface
<><
Note: I've noticed that in trying to manipulate Excel from Access that there are some things that work when coded in the Excel VBE but not in the Access VBE. Is it just me or have others had similar experiences? Thanks again!
I'm having some trouble with Access to Excel automation. This site has been extremely helpful. I've searched for many a solution on this site and found many answers. Now I need to ask a specific question. I'll be as brief and to the point as possible.
Objective: Create a monthly Excel spreadsheet that takes data from Access and makes a new tab for every grouping (Pyramid) in the recordset. Then I wish to copy each Pyramid's records into the corresponding tab in Excel. I am working in Access 2000 and Excel 2000. I prefer DAO because I haven't learned ADO yet.
Below is the code I've written so far. Please see the red code and my bolded comments. I took the CopyFromRecordset method right out of Access help. But it's not working??? Perhaps I'm not setting the range right? Thanks in advance for your assistance.
Code:
Sub CreateXLSheets()
Dim db As Database
Dim rsID As Recordset
Dim rsXLData As Recordset
Dim strSQL As String
Dim strIDNo As String
Dim objXL As Object
Dim rngXL As Excel.Range
Set db = CurrentDb
Set objXL = New Excel.Application
'---Grab the Pyramid codes from recordset
strSQL = "SELECT DISTINCT Pyramid FROM qryAuditReportwDivCodes WHERE Pyramid = " & Chr(34) & "SUPHQ" & Chr(34)
Set rsID = db.OpenRecordset(strSQL, dbOpenDynaset)
strIDNo = rsID!Pyramid
objXL.SheetsInNewWorkbook = 1
objXL.Workbooks.Add
Do Until rsID.EOF
strSQL = "SELECT EE, LastName, FirstName, Feb, Mar FROM qryAuditReportwDivCodes" & _
" WHERE Pyramid = " & Chr(34) & strIDNo & Chr(34) & " ORDER BY EE ASC"
Set rsXLData = db.OpenRecordset(strSQL, dbOpenDynaset)
'put into an XL worksheet tab here
objXL.ActiveSheet.Name = strIDNo
Set rngXL = objXL.ActiveSheet.Range("A1"
rngXL.CopyFromRecordset rsXLData
the code in red here is where I am hanging up I get
error 430 Class does not support Automation or does not support expected interface
Code:
objXL.Worksheets.Add
objXL.Visible = True
rsXLData.Close
Set rsXLData = Nothing
rsID.MoveNext
Loop
rsID.Close
Set rsID = Nothing
objXL.DisplayAlerts = False
objXL.ActiveWorkbook.Close
objXL.DisplayAlerts = True
objXL.Quit
Set objXL = Nothing
Set rngXL = Nothing
db.Close
Set db = Nothing
End Sub
<><
Note: I've noticed that in trying to manipulate Excel from Access that there are some things that work when coded in the Excel VBE but not in the Access VBE. Is it just me or have others had similar experiences? Thanks again!