How to save reports automatically

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

  • Posted 4 August 2017, 2:32 pm EST

    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.

    Thanks
  • Replied 4 August 2017, 2:32 pm EST

    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")

        username = txtUserName.Text
        password = txtPassword.Text
        Set rstLogin = MyDB.OpenRecordset("SELECT * FROM Login")
        If Not rstLogin.eof And Not rstLogin.BOF Then
            rstLogin.MoveFirst
            While Not rstLogin.eof
                If username = rstLogin("USERNAME") And password = rstLogin("PASSWORD") Then
                    G_LOGIN = True
                    Unload Me
                    frmMDIMain.Show
                   
                   
                    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
                            rstNewReports.MoveFirst
                           
                            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

                            '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.

  • 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

    That does not work, my report still shows and I can't have that happening!!!
  • 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.

    'setup your report

    Set oPDF = New ARExportPDF
    oPDF.FileName = filename   'I usually use a Common Dialog
    oPDF.JPGQuality = 50       'Best mix of size and quality in my case
    rptReport.Run False        'runs without showing
    oPDF.Export rptReport.Pages

    Set oPDF = Nothing
    Set rptReport =
    Nothing
  • Replied 4 August 2017, 2:32 pm EST

    I don't see any code for setting up the rptFormativeReport object in your code? Where are you calling the report object's Run method? Is rptFormativeReport your report design name or is it a newly instantiated report object?
  • 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.
  • Replied 4 August 2017, 2:32 pm EST

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

    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.
  • 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

    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.
  • 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?
  • 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 our FTP site or email it to activereports.support@datadynamics.com.
  • Replied 4 August 2017, 2:32 pm EST

    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

    rptFormative.Hide

    So now Run, Nothing, and Hide don't work as advertised...anyone?
  • 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.
Need extra support?

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

Learn More

Forum Channels