Link to home
Start Free TrialLog in
Avatar of Heliumyap
Heliumyap

asked on

Report sections do not match data source

experts,

I am generating a report from Data Report from VB6 SP4. I have a report that have a grouping within. I understand that i need to set a group from the Data Environment if i am using one the DataEnvironment. However, i am using ADO directly.

I have codes to generate my own ADO and attach it to the report. It work without the Group header/section.

Anyone knows how to avoid "Report sections do not match data source" error in this case?
 
My codes are like:
    set rsRegion = ...................

    With rptTop10    ' Bind the Recordset to the Report
        Set .DataSource = rsRegion
        .DataMember = rsRegion.DataMember
        DoEvents
        .Show
    End With

Avatar of Pi7
Pi7

The code below is a sample code that should guide you.Since you say you're using ADO i suppose you're familiar with the code below
Copy and paste the code below into your code module, adapting it to your program by making the necessary changes


Dim rs As New ADODB.Recordset
Dim cn As New ADODB.Connection
Dim Str As String
Private Sub Form_Load()
Dim i As Integer
With cn
    .CursorLocation = adUseClient
    .ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = C:\Test.mdb"
    .Open
End With
Str = "Select * From Table1"
rs.Open Str, cn, adOpenDynamic, adLockOptimistic, adCmdText
Set DataReport1.DataSource = rs
DataReport1.DataMember = ""
With DataReport1.Sections("Section1")
For i = 1 To .Controls.Count
If TypeOf .Controls(i) Is RptTextBox Then
    .Controls(i).DataField = rs.Fields("ID").Name
    .Controls(i).DataMember = ""
End If
Next i
End With
DataReport1.Refresh
Me.Hide 'hide Form1
DataReport1.Show
End Sub
Avatar of Heliumyap

ASKER

This will not solve the problem i meantion earlier. The error message arises when i put something into the HEADER/GROUP in the Data Report.

So i presume this must be a difficult question...so i increase it to 400 points now.
Make sure that in your Data Environment that on the properties tab you have the correct grouping set up... then do something like this

With DataReport1
        Set .DataSource = Nothing
        .DataMember = ""
        Set .DataSource = rst1
        With .Sections("Command1_Detail").Controls
            .Item(1).DataMember = ""
            .Item(1).DataField = rst1.Fields(0).Name
            .Item(2).DataMember = ""
            .Item(2).DataField = rst1.Fields(1).Name
            .Item(3).DataMember = ""
            .Item(3).DataField = rst1.Fields(2).Name
            .Item(4).DataMember = ""
            .Item(4).DataField = rst1.Fields(3).Name
            .Item(5).DataMember = ""
            .Item(5).DataField = rst1.Fields(4).Name
            .Item(6).DataMember = ""
            .Item(6).DataField = rst1.Fields(5).Name
            .Item(7).DataMember = ""
            .Item(7).DataField = rst1.Fields(6).Name
            .Item(8).DataMember = ""
            .Item(8).DataField = rst1.Fields(7).Name
            .Item(9).DataMember = ""
            .Item(9).DataField = rst1.Fields(8).Name
            .Item(10).DataMember = ""
            .Item(10).DataField = rst1.Fields(9).Name
            .Item(11).DataMember = ""
            .Item(11).DataField = rst1.Fields(10).Name
            .Item(12).DataMember = ""
            .Item(12).DataField = rst1.Fields(11).Name
            .Item(13).DataMember = ""
            .Item(13).DataField = rst1.Fields(12).Name
           
        End With
    End With
I guess my question is like a mud. So let me make it clearer with an example:

In the Data Report, i have Page Header&footer, Report Header&footer and Country header&footer

First, i have two RptTextBox in the Detail section Displaying the customer name and thier transaction amount
Second, i have thier country name display inside the Country header

My ADO recordset have these fields:

country, custName and transaction

i did pay a visit to MSDN article but doesnt work:
http://support.microsoft.com/default.aspx?scid=kb;en-us;289793

i cannot follow fully to the article because i do not use any command and i have more than one RptTextBox in the Detail section. i have no idea how to map them.

this morning, the error message "Report sections do not match data source" appears in my nightmare! SOS!!!!




Oh.....i just found out my mistake and the solution.

By using ADO (with notmal SQL) is good with no problem having that no group section.

But when i have a group, i need to use ADO with SHAPE. And here is the code like:

Dim rs As ADODB.Recordset
Dim child_rs As ADODB.Recordset

    Set rs = New ADODB.Recordset
    rs.LockType = adLockBatchOptimistic
    rs.Open _
        "SHAPE APPEND " & _
        "  New adVarChar(10) As ParentDay," & _
        "  ((SHAPE APPEND" & _
        "    New adVarChar(10) As ChildDay," & _
        "    New adVarChar(10) As Name," & _
        "    New adInteger As Amount)" & _
        "  RELATE ParentDay to ChildDay) As Child", _
        "Provider=MSDataShape;Data Provider=None"

    rs.AddNew Array("ParentDay"), Array("Monday")
    rs.AddNew Array("ParentDay"), Array("Tuesday")

    Set child_rs = rs("Child").Value
    child_rs.AddNew Array("ChildDay", "Name", "Amount"), Array("Monday", "Rod", -1.11)
    child_rs.AddNew Array("ChildDay", "Name", "Amount"), Array("Tuesday", "Rod", 2.22)
    child_rs.AddNew Array("ChildDay", "Name", "Amount"), Array("Monday", "Michelle", 11.11)
    child_rs.AddNew Array("ChildDay", "Name", "Amount"), Array("Tuesday", "Cobe", -22.22)

    Set rptTest.DataSource = rs
    rptTest.Show vbModal

    rs.Close

This will work fine as long as all the textbox in Data report has the data field define.
Err...in this case, what happen to the Points?
You can ask for a refund in community support or distribute them however you see fit.
ASKER CERTIFIED SOLUTION
Avatar of PashaMod
PashaMod

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial