Print from VB code without displaying viewer

Posted by: jim on 23 October 2017, 10:27 am EST

    • Post Options:
    • Link

    Posted 23 October 2017, 10:27 am EST

    Can I create and print a V9 section report without displaying it in the viewer using only VB code? The report needs to be created and printed with only one user click on a button. Is this possible?

  • Posted 24 October 2017, 11:16 am EST

    Hello,

    Yes, you can do that. You only need to run the report and then you can print it using the code as follows:

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

    Dim sectionReport As New GrapeCity.ActiveReports.SectionReport()

    Dim xtr As New System.Xml.XmlTextReader(“…..\PurchaseOrder.rpx”)

    sectionReport.LoadLayout(xtr)

    xtr.Close()

    sectionReport.Run()

    Dim sectionDocument = sectionReport.Document

    ’ sectionDocument.Print ’ OR

    PrintExtension.Print(sectionDocument, True, True)

    End Sub

    I hope it helps.

    Thanks,

    Deepak Sharma

  • Posted 24 October 2017, 8:35 pm EST

    Thanks for your response, Deepak.

    I’m a newbie.

    I’m using Visual Studio 2013 and all report files have the extension .vb. The line to dim xtr cannot find the file if I use the .vb suffix. There are no files with the .rpx suffix.

    It is also looking in the bin/release file for the project, but no report files are stored there.

    Do I have to create a file with the .rpx suffix? What does it contain?

    Jim Foy

  • Posted 25 October 2017, 2:18 am EST

    Hi Jim,

    Rpx is the extension for section based ActiveReport. You can design the report with ActiveReports Designer or create a report in code. In both cases the above approach will work fine.

    Thanks,

    Deepak Sharma

  • Posted 25 October 2017, 6:36 pm EST

    I’ve designed all reports in the designer embedded in Visual Studio. I don’t see any options to save the file as a separate .rpx file. All are saved as .vb files. This is apparently the critical part of your code because the .rpx file has to be resident in bin file for release or debug before the code will work.

    Sorry for being dense.

    Jim Foy

  • Posted 26 October 2017, 11:41 am EST

    Hello,

    It looks you are working with the Code based section report. In this case you can use the code as follows to print the report directly.

    Dim rpt = New SectionReport1()

    rpt.Run(False)

    Dim sectionDocument = rpt.Document

    sectionDocument.Print(True, True, False)

    Where SectionReport1 is your vb report.

    Thanks,

    Deepak Sharma

  • Posted 26 October 2017, 7:28 pm EST

    Deepak,

    This looks very promising, but won’t have time to try it until the weekend. Will let you know how it works.

    Thanks for sticking with me.

    Jim Foy

  • Posted 27 October 2017, 9:12 am EST

    Deepak,

    I couldn’t wait to try the code and with partial success!!

    For the first two section reports I tried, it worked perfectly, but presented the print dialog until the code was changed to (false,false,false).

    On the next section report, gave the error message: “Print is not a member of GrapeCityActiveReports.document.sectiondocument” The reports are section documents, but some say print won’t work?!? Any insights?

    Jim Foy

  • Posted 27 October 2017, 9:53 am EST

    Deepak,

    DUH! I hadn’t imported Grape City Active Reports on the form I wanted to initiate the print. Did that, and now it works perfectly!

    Thanks so much for your help.

    Jim Foy

  • Posted 28 October 2017, 1:44 am EST

    Hi Jim,

    Glad that it worked for you!

    Thanks,

    Deepak Sharma

Need extra support?

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

Learn More

Forum Channels