Hi all,I'm building a VB6 DLL method that will receive the RC object and read the column names and records, then populate Excel. When the RC columns are moved to a different position or columns are removed, they don't match up in Excel with what is showing in the RC.
Here's a simple example. Columns in original order: Check box, ID, Name, Manager, Type The user clicks a button which runs VB6 code to load the column names and records to Excel. This works fine at this point. Columns and data are in the correct Excel columns.
The user then wants to change the order of the columns. They move the RC Type column in between Name and Manager. Now the RC column layout is: Check box, ID, Name, Type, Manager
The user clicks the button again to send to Excel. The column names and record values go to Excel fine, but the data doesn't match up with the column name.
Here's some screen shots.
RC before column move:
Excel before moving RC column:
RC after moving column: Data appears correctly in RC object.
Excel after RC column move:
In the screen shot above, notice the Type column contains the data for the Manager column.
This is the problem I'm having. The data doesn't match up with the column name.
Here's a partial VB6 code listing that reads the reportControl object, extracts the record data. populates Excel , then reads the Columns object and populates Excel with the column names.
================================== ExportSelected = Me.ckExportSelected.Value With oSheet If ExportSelected = True Then '// if records checked 'preset the starting row for data x = 6 'read every record in the Records object For i = 0 To RC.Records.Count - 1 Set Record = RC.Records.Record(i) 'left most column should be the checkbox 'check the state of it: 1=checked (ie: user selected the record) If Record.Item(0).CheckboxState = 1 Then For j = 1 To RC.Columns.Count .Cells(x, j) = Record.Item(j - 1).Value Next j x = x + 1 End If Next i Else '// all records in view For i = 0 To RC.Records.Count - 1 Set Record = RC.Records.Record(i) For j = 1 To RC.Columns.Count .Cells(i + 6, j) = Record.Item(j - 1).Value Next j Next i End If 'format Columns For i = 0 To RC.Columns.Count - 1 'set column title and set as Bold .Cells(5, i + 1) = RC.Columns(i).Caption .Cells(5, i + 1).Font.Bold = True 'column alignment Select Case RC.Columns.Column(i).Alignment Case xtpAlignmentCenter .Columns(i + 1).HorizontalAlignment = xlCenter Case xtpAlignmentRight .Columns(i + 1).HorizontalAlignment = xlRight Case Else .Columns(i + 1).HorizontalAlignment = xlLeft End Select Next i End With ============================================ Maybe it would be better to read the columns in a For loop and inside that, read the Records object in a For loop.
Any help on this would be appreciated.
Regards, Mark Stuart
------------- Regards,
Mark Stuart
Product: Xtreme SuitePro (ActiveX) v13.2.1
Platform: WinXP (32bit)/Win7 (64bit)
Language: VB6 (SP6), Magic eDeveloper v9.4, uniPaaS v1.9
|