VB6 vsFlexGrid 8 VSReport page for each record in ADO recordset

Posted by: computers on 19 January 2018, 9:46 am EST

    • Post Options:
    • Link

    Posted 19 January 2018, 9:46 am EST

    I would like to render a report for every ADO record by looping through the records. I’m able to render a report for a single record, but can’t work out how to render for each record in the ADO recordset to display a page for record.

    Any help would be very much appreciated.

  • Posted 21 January 2018, 10:08 pm EST

    Hi,

    What you can do here is:

    1. Design a report and bind it to your data source.
    2. In report’s detail section, place the fields you want to include in the report and bind them with the corresponding columns in the data source.
    3. Set the ForcePageBreak property of the detail section to ‘vsrAfter’. This will ensure that a page break is inserted after the section.

    Please refer the following documentation links for more information on this:

    http://help.grapecity.com/componentone/NetHelp/vsviewreports8/creatingabasicreportdefinition.html

    http://help.grapecity.com/componentone/NetHelp/vsviewreports8/webframe.html#forcepagebreakpropertysection.html

    Hope it helps.

    Thanks,

    Pragati

  • Posted 21 January 2018, 11:49 pm EST

    Thank you for the reply.

    I want to avoid using the report designer and use code. The project requested of me will require the user to select options and the report will display those options with the appropriate data records. Is this possible?

    The current code dumps all the data on one page and I need to separate into individual pages per record.

    Dim strDataFile As String
    Dim f As VSReport8LibCtl.Field
    
    strDataFile = "C:\Users\Toby\Documents\VB6\TestRepot\Data\data.mdb"
    
    With Adodc1
        .ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
        "Persist Security Info=False;JET OLEDB:Database Password=;Data Source=" & strDataFile & _
        "; Mode=Read|Write"
        .CursorLocation = adUseServer
        .CursorType = adOpenStatic
        .CommandType = adCmdText
        .RecordSource = "SELECT * FROM MainData"
        .Refresh
    End With
    
    Adodc1.Recordset.MoveFirst
    
    For iRecord = 1 To Adodc1.Recordset.RecordCount - 1
            
            With VSReport1.Sections(vsrDetail)
                .Visible = True
                Set f = .Fields.Add("FldRecord", Adodc1.Recordset.Fields(0), 1000, 2000, 1500, 320)
                f.Align = vsrLeftMiddle
                f.FontSize = 10
                f.Font.Name = "Arial"
                f.BorderStyle = vsrBSSolid
            
            End With
        Adodc1.Recordset.MoveNext
    Next iRecord
    
    VSReport1.Render VSPrinter1
    End Sub
    
    
  • Posted 22 January 2018, 6:15 pm EST

    Hi,

    Yes, this is definitely possible. Since you want to generate a new page for every record in your data source, please set detail’s ForcePageBreak property to ‘vsrAfter’. Hence, your code will look like the following:

    
    For iRecord = 1 To Adodc1.Recordset.RecordCount - 1
            
            With VSReport1.Sections(vsrDetail)
                .Visible = True
                .ForcePageBreak=2
                Set f = .Fields.Add("FldRecord", Adodc1.Recordset.Fields(0), 1000, 2000, 1500, 320)
                f.Align = vsrLeftMiddle
                f.FontSize = 10
                f.Font.Name = "Arial"
                f.BorderStyle = vsrBSSolid
            
            End With
        Adodc1.Recordset.MoveNext
    Next iRecord
    
    

    Let me know if you still face any issues.

    Thanks,

    Pragati

  • Posted 23 January 2018, 4:22 am EST

    Hi Pragati,

    Sorry that doesn’t work.

    I tried .ForcePageBreak with different values in various places with the code before contacting the forum. I assumed that I was doing something wrong, but there must be another issue. Any suggestions?

    Are there any VSPrinter properties to tweak or is all based on the VSReport control?

    Jason

  • Posted 24 January 2018, 8:10 pm EST

    Hi Jason,

    Yes, it depends on the layout of the report only. Can you please try setting the ForcePageBreak property outside the loop and see if that makes any difference? Also, make sure this property is not being reset anywhere else in the project.

    In case the problem persists, please share a stripped down application demonstrating the behavior. I would like to investigate this further.

    Thanks,

    Pragati

  • Posted 24 January 2018, 10:50 pm EST

    Hi Pragati,

    I couldn’t get the forcepagebreak to work outside of the loop either. I’ve attached a stripped down project and data as requested.

    Thank you,

    Jason

    Project1.zip

  • Posted 28 January 2018, 10:32 pm EST

    Hi Jason,

    Thank you for sharing the project. Since the report is not bound to any data source, it generates only one page and hence, the records from the ADO RecordSet are overlapped.

    In order to render every record of your recordset on different page in the report, you would first need to set report’s DataSource as follows:

    
    VSReport1.DataSource.ConnectionString = Adodc1.ConnectionString
    VSReport1.DataSource.RecordSource = Adodc1.RecordSource
    
    

    Now, set the Detail’s ForcePageBreak property to ‘After’.

    I have made few modifications in your application and it works as desired. Please find the same attached.

    Thanks,

    Pragati

    Modified_Project.zip

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels