Hi all. I have been lurking for a while and have learned much from the excel forum. Thanks.
More info here as well
I have attached a sample database which uses the excel functions. If you want to look at the underlying data, hold down Shift Key while opening, as I have a form loading on start.
I am getting the "unable to set FormulaArray property of Range class" error when doing the below code. When I place my breakpoint I can trace to this line:
objResultsRange.FormulaArray = objExcel.Transpose(varResults).
Sometimes this works with some ranges but does not work with others. Any help or insight would be greatly appreciated.
strQuery = "SELECT [Detail].[Menu Item] AS ItemSold, Sum([Detail].[Quantity]) AS TotalQty, Sum([Detail].[Item Price]) AS TotalSale, "
strQuery = strQuery & "[Detail].[Department Name] AS DeptName, [Detail].[Category Name] AS CategoryName "
strQuery = strQuery & "FROM [Detail] "
strQuery = strQuery & "WHERE (((CDate([Date])) >= #" & datStartDate & "# And (CDate([Date])) <= #" & datEndDate & "#)) "
strQuery = strQuery & "GROUP BY [Detail].[Department Name], [Detail].[Category Name], [Detail].[Menu Item] "
strQuery = strQuery & "ORDER BY [Detail].[Department Name], [Detail].[Category Name], [Detail].[Menu Item];"
Set rstResults = CurrentDb.OpenRecordset(strQuery)
varResults = rstResults.GetRows(2 ^ 15)
rstResults.Close
Set rstResults = Nothing
Set objExcel = CreateObject("Excel.Application")
objExcel.Workbooks.Add
Set objResultsWorkbook = objExcel.Workbooks(objExcel.Workbooks.Count)
Set objResultsSheet = objResultsWorkbook.Worksheets("Sheet1")
Set objResultsRange = objResultsSheet.Range("A2:E" & 2 + UBound(varResults, 2))
objResultsRange.FormulaArray = objExcel.Transpose(varResults)
objResultsSheet.Range("A1").Value = "Item Sold"
objResultsSheet.Range("B1").Value = "Total Qty"
objResultsSheet.Range("C1").Value = "Total Sale"
objResultsSheet.Range("D1").Value = "Department Name"
objResultsSheet.Range("E1").Value = "Category Name"
objResultsSheet.Range("A:E").Columns.AutoFit
objExcel.Visible = True
Set objResultsRange = Nothing
Set objResultsSheet = Nothing
Set objResultsWorkbook = Nothing
Set objExcel = Nothing
Bookmarks