Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Print report to HTML on 1 page

Status
Not open for further replies.

patrickstrijdonck

Programmer
Jan 18, 2009
97
NL
Hi all,

Im trying to export a access report to HTML, so far that is working with with the below code. However, on a specific time, a mail must be sent to some people with this HTML file.
THIS is going fine aswell!!!

The actual problem is, this report is larger then 1 page, it seperates into multiple pages. which creates multiple HTML files, while the code is just sending 1 file.

Can this be changed somehow so that it creates just 1 HTML file with all data in it??

Code:
if (DateTime.Now.Hour == 11 && DateTime.Now.Minute == 59)
                {
                    
                    
                        notifyIcon1.Visible = true;
                        this.Hide();
                        //CODE FOR EMAIL
                        // Get the reports
                        // we have a valid file name so we now need to
                        // populate the list box with available reports
                        listBox1.Items.Clear();

                        // create an application object.
                        MsAccess.Application app = new MsAccess.Application();
                        // open the access database file.
                        dlg.Text = Properties.Settings.Default.serverdb;
                        app.OpenCurrentDatabase(dlg.Text, false, "");

                        string sql = "SELECT [Name] FROM MSysObjects WHERE Type = -32764";
                        dao.Database db = app.CurrentDb();
                        // query the database for all the reports.  all this data is
                        // contained in the MSysObejcts table which is invisible through
                        // the table listing in access.
                        dao.Recordset rs = db.OpenRecordset(sql, Type.Missing, Type.Missing, Type.Missing);
                        // go through and add all the reports to the list box.
                        while (!rs.EOF)
                        {
                            listBox1.Items.Add(rs.Fields[0].Value);
                            rs.MoveNext();
                        }

                        // clean up
                        rs.Close();
                        rs = null;
                        db.Close();
                        db = null;
                        app.CloseCurrentDatabase();
                        app = null;


                        //Select the correct report
                        listBox1.SelectedItem = "Outstanding_Calls";

                        //Set current Database
                        dlg.Text = Properties.Settings.Default.serverdb;

                        //Print to HTML
                        string report = Properties.Settings.Default.report;
                        string fileName = Properties.Settings.Default.report + ".html";

                        // create an application object.
                        MsAccess.Application app2 = new MsAccess.Application();
                        // open the access database file.
                        app2.OpenCurrentDatabase(dlg.Text.Trim(), false, "");
                        app2.Visible = false;
                        // open the report
                        app2.DoCmd.OpenReport(report, Microsoft.Office.Interop.Access.AcView.acViewPreview,
                            Type.Missing, Type.Missing, MsAccess.AcWindowMode.acWindowNormal, Type.Missing);
                        // export the report to an HTML file
                        app2.DoCmd.OutputTo(MsAccess.AcOutputObjectType.acOutputReport,
                            report, "HTML (*.html)", fileName, Type.Missing, Type.Missing, Type.Missing);

                        // cleanup
                        app2.CloseCurrentDatabase();
                        app2 = null;
}

P.S. Code is not complete here, but this is the Export part.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top