September 12, 2004 at 3:09 pm
I want to present different reports in Excel. The reports will not have fixed quantity of columns. The columns are timeperiods and the rows keyvalues. I would like to use the method CopyFromRecordset in Excel2003, but I don't know how to create the dynamic recordset. If I understand it correct, to use this method the recordset has to have all the columns defined I will have in the report but the number of columns will vary. Currently I use a fiex recordset that I loop through on the VBA Client, but I would like to skip this to make the presentation faster by using this Copy method |
September 13, 2004 at 6:29 am
Before you start writing this code you should check out the Data, Import External Data menu item. This will allow you to create a query or connect to an existing SQL Server View to get a recordset. The user can refresh the data when needed.
You can send your data (as pairs of key values and time periods) to a raw data sheet in your workbook and then create a Pivot Table on a separate sheet that will group your time periods automatically into columns. For example, it will automatically create years, quarters and month summary groups from weekly data. The number of groups will adjust automatically whenever the raw data is updated.
HTH
Dean
September 13, 2004 at 7:10 am
CopyFromRecordset does not take out any headings into Excel, so you have 2 options,
1. Use a template with the column headings predefined
2. Loop through the fields collection of the recordset and enter the field name into the cells in the first row
Then set the cursor to cell where you want the data to be put and use the copyfromrecordset
This bit of code does the second option, you just pass an excel worksheet and an ADODB.recordset
Function RecordsetToExcelSheet(rst As ADODB.Recordset, xlSheet As Excel.Worksheet, Optional intFirstRow As Integer = 1)
Dim i As Integer
For i = 0 To rst.Fields.Count - 1
xlSheet.Cells(intFirstRow, i + 1) = rst.Fields(i).Name
Next i
xlSheet.Cells(intFirstRow + 1, 1).CopyFromRecordset rst
End Function
September 13, 2004 at 9:15 am
Just remember that in Excel, you have a limit of 65,536 rows of data that can be inserted.
September 13, 2004 at 9:54 am
I've just dynamically created a recordset (RS):
I still have 2 problems
The first 50 % of the data that I send to the client will be double values but the rest will be string values (Formulas).
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply