How to save reports automatically

Posted by: beebs on 4 August 2017, 2:32 pm EST

  • Posted 4 August 2017, 2:32 pm EST

    <font size="2">How can I have the user click on a button and save a report without them ever seeing it or previewing it?  The report needs to be in the native ActiveReport format so then I can export it directly from the saved location into a pdf document and then delete the native format.  Again, this all has to happen without them seeing the report.

  • Replied 4 August 2017, 2:32 pm EST

    <font size="2">That does not work, my report still shows and I can't have that happening!!!</font>
  • Replied 4 August 2017, 2:32 pm EST

    You would not even really need the native RDF file if all you are going to do is delete it after PDF creation.  You can go straight from a reports Pages collection to a PDF.

    <font face="Courier New"><font color="#008000">'setup your report</font>

    <font color="#0000ff">Set</font> oPDF = <font color="#0000ff">New</font> ARExportPDF
    oPDF.FileName = filename   <font color="#008000">'I usually use a Common Dialog
    </font>oPDF.JPGQuality = 50       <font color="#008000">'Best mix of size and quality</font> <font color="#008000">in my case
    </font>rptReport.Run <font color="#0000ff">False</font>        <font color="#008000">'runs without showing</font>
    oPDF.Export rptReport.Pages <font color="#008000">

    </font><font color="#000000"><font color="#0000ff">Set</font> oPDF = <font color="#0000ff">Nothing</font>
    <font color="#0000ff">Set</font> rptReport = </font><font color="#0000ff">Nothing</font></font>
  • Replied 4 August 2017, 2:32 pm EST

    Sorry about missing the run. I was expecting it higher in the code. I don't see any code for setting up the rptFormativeReport object in your code. -- Is rptFormativeReport your report's class name or is it a newly instantiated report object?
    <span id="_ctl0_MainContent_PostFlatView"><span><span id="_ctl0_MainContent_PostFlatView"><span><font size="2"><font face="Arial" size="3"> </font></font></span></span></span></span>
  • Replied 4 August 2017, 2:32 pm EST

    <font size="2">Private Sub btnLogin_Click()
        Dim username As String
        Dim password As String
        Dim currentDir As String
        Dim today As String
        Dim oPDF As ARExportPDF
        currentDir = App.Path
        today = Now()
        today = Format(today, "mm-dd-yyyy")</font>

    <font size="2">    username = txtUserName.Text
        password = txtPassword.Text
        Set rstLogin = MyDB.OpenRecordset("SELECT * FROM Login")
        If Not rstLogin.eof And Not rstLogin.BOF Then
            While Not rstLogin.eof
                If username = rstLogin("USERNAME") And password = rstLogin("PASSWORD") Then
                    G_LOGIN = True
                    Unload Me
                    Set rstNewReports = MyDB.OpenRecordset("SELECT * FROM Formative_Lookup WHERE New = True")
                    If Not rstNewReports.eof And Not rstNewReports.BOF Then
                        If MsgBox("There were new formative observations found, would you like to email these reports now?", _
                           vbQuestion + vbYesNo + vbDefaultButton1) = vbYes Then
                            G_NEW = True
                            'Create report folder named for today's date
                            If Dir$(currentDir & "\Generated Reports", vbDirectory) = "" Then
                                MkDir currentDir & "\Generated Reports"
                            End If
                            If Dir$(currentDir & "\Generated Reports\" & today, vbDirectory) = "" Then
                                MkDir currentDir & "\Generated Reports\" & today
                            End If
                            currentDir = currentDir & "\Generated Reports\" & today</font>

    <font size="2">                        'Export report to pdf document
                            Set oPDF = New ARExportPDF
                            oPDF.FileName = currentDir & "\" & today & ".pdf"
                            oPDF.JPGQuality = 100
                            rptFormativeReport.Run False
                            oPDF.Export rptFormativeReport.Pages
                            Set oPDF = Nothing
                            Set rptFormativeReport = Nothing

    I will add that my application is an MDI application and I've made the report an MDI child, not sure if this really matters though.</font>

  • Replied 4 August 2017, 2:32 pm EST

    Coul you post the code you're using? What's the startup object for your project? The .Run will run the report without displaying it on the screen.
  • Replied 4 August 2017, 2:32 pm EST

    <font face="Arial" size="3">I don't see any code for setting up the </font><span id="_ctl0_MainContent_PostFlatView"><span><font size="2"><font face="Arial" size="3">rptFormativeReport object in your code? Where are you calling the report object's Run method? Is </font></font></span></span><span id="_ctl0_MainContent_PostFlatView"><span><font size="2"><font face="Arial" size="3">rptFormativeReport your report design name or is it a newly instantiated report object? </font></font></span></span><span id="_ctl0_MainContent_PostFlatView"><span></span></span><span id="_ctl0_MainContent_PostFlatView"><span><font size="2">
  • Replied 4 August 2017, 2:32 pm EST

    <font size="2">what do you mean...I clearly call False.  rptFormativeReport is my reports design name.  What should I be doing if what I'm doing is wrong???</font>
  • Replied 4 August 2017, 2:32 pm EST

    You need to setup your report...that means dimensioning and instantiating a report object.  It is NOT a good idea to use a design name for an object name, i.e. Dim String as String or rptOne as rptOne.

    Do you have a .Show later in your code that could be causing the report to rerun and show?
  • Replied 4 August 2017, 2:32 pm EST

    <font size="2">I'm not bashing ActiveReports, I'm just simply explaining my stance on the issue.  I have verified that nothing is showing the report, but I guess, according to you, I must be wrong.  The pdf exporting does work fine...your code works great, except the fact that the report shows.  I do think ActiveReports is great, other than this particular problem I'm having with the run call.</font>
  • Replied 4 August 2017, 2:32 pm EST

    <font size="2">I added this line to the beginning of my function:

    Dim rptFormative As New rptFormativeReport

    and have replaced all previous calls of rptFormativeReport with rptFormative.  As for any addition .Show calls for the report...there are none.  I guess I'll just have to inform my client there is no way to hide the reports, even though he is not going to be happy about that, or find different reporting software that will do what I need it to do.</font>
  • Replied 4 August 2017, 2:32 pm EST

    We're more than happy to look at your entire project! Just archive the entire project in a zip file. Once you've archived it, you can either post it to this thread using an attachment, upload it to <u>our FTP site</u> or email it to
  • Replied 4 August 2017, 2:32 pm EST

    <font size="2">Would someone be interested in looking at my project?  This is just too upsetting.  I can't even close my report out by setting it to nothing:

    Set rptFormative = Nothing

    or even hiding the form


    So now Run, Nothing, and Hide don't work as advertised...anyone?</font>
  • Replied 4 August 2017, 2:32 pm EST

    The .Run will not show the report.  In your case here there appears to be a bug in that it does.  I would suggest upgrading the latest release of AR2 if you have not already done so to see if that has any affect.
  • Replied 4 August 2017, 2:32 pm EST

    What you tell your own clients and what your use for reporting software is of course your own choice.

    ActiveReports is a very solid product that has been in use by my company for over 5 years, the majority of that time with myself as the primary developer, with very little trouble I might add.  I also plan to continue using it for the long haul as well as it literally allows me to do some amazing things in a straight forward manner, such as creating PDFs.

    The code I gave you is used by my company also daily to generate PDFs to send to our clients via email.  I know it works.  That is not a complete code paste that you posted so I cannot verify or see anything before or after that might be causing the report to show.  I would encourage you to use the VB6 IDE debugger to find out the exact point(s) at which the report shows.  I have a sneaky feeling that you have either missed a .Show someplace or are loading it into a viewer control or calling it from another report/form, etc.  Reports do not simply show themselves with out explicit instructions to do so.
Need extra support?

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

Learn More

Forum Channels