Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 25th, 2004, 11:03 AM
Registered User
 
Join Date: Nov 2003
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default exporting report from crystal to notepad

hello every body
i'm new on this zone
i have a problem with reports
actually my application is accessing database from MS-ACCESS and i'm getting reports on crystal report.
but i have a new problem .
my new client has dot matrix printer so report printing is too slow.
is there any way to have reports in ascii text format on notepad.
please help me.

you can send me mail at:
[email protected]
 
Old June 26th, 2004, 05:00 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,093
Thanks: 1
Thanked 12 Times in 11 Posts
Default

Hello,

You could do it as a two step process: export and print.

First export the report to plain text if your version of Crystal Reports supports that export format. Not all versions of Crystal Reports will export to plain text. For example, I'm using Crystal Reports for Visual Studio .NET, and the only export formats available are:

Adobe Acrobat (.pdf)
Crystal Reports for Visual Studio .NET (.rpt)
HTML 3.2 and 4.0 (.html)
Microsoft Excel (.xls)
Microsoft Rich Text (.rtf)
Microsoft Word (.doc)

Version 10, however, has additional export formats, including text/CSV, XML, and Lotus.

I don't know what front-end langauge you are using but the following is in C#. The code toggles off the toolbar export button in the CRViewer's Load event. The export and print to NotePad is accoplished
by clicking a command button 'Export Report' placed on the form that hosts your crystal reports viewer.

The code below but first I needed to drag a Process Component from the Toolbox to the form's component tray. Then:

******Code******

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

// Add this using directive.
using System.Diagnostics;

namespace CrystalReportsTest
{
    public class Form1 : System.Windows.Forms.Form
    {
        private System.Diagnostics.Process notePad;
        private CrystalDecisions.Windows.Forms.CrystalReportViewer CrystalReportViewer1;
        private System.Windows.Forms.Button cmdExportToNotePad;
        private System.ComponentModel.Container components = null;

        // These are the Win32 error code for file not found or access denied.
        const int ERROR_FILE_NOT_FOUND =2;
        const int ERROR_ACCESS_DENIED = 5;

        private void cmdExportReportNotePad_Click(object sender, System.EventArgs e)
        {
            // Invoke the Exort report dialog. Be sure and save the text
            // report to the My Documents directory. That is where the
            // printing routine will look for it.
            this.CrystalReportViewer1.ExportReport();

            //Print exported ascii report in NotePad
            PrintDoc();
        }

        public void PrintDoc()
        {
            Process notePad = new Process();
            try
            {
                // Get the path that stores user documents. [My Documents]
                string myDocumentsPath =
                        Environment.GetFolderPath(Environment.SpecialFolde r.Personal);

                // The exported file to be printed is assigned here.
                notePad.StartInfo.FileName = myDocumentsPath + "\\TestNotePad.txt";
                notePad.StartInfo.Verb = "Print";
                notePad.StartInfo.CreateNoWindow = true;
                notePad.Start(); // Process opens NotePad and Prints exported text report.
            }
            // Note that if your word processor generates exceptions
            // such as this, they are handled first.
            catch (Win32Exception e)
            {
                if(e.NativeErrorCode == ERROR_FILE_NOT_FOUND)
                {
                    Console.WriteLine(e.Message + ". Check the path.");
                }
                else if (e.NativeErrorCode == ERROR_ACCESS_DENIED)
                {
                    Console.WriteLine(e.Message +
                            ". You do not have permission to print this file.");
                }
            }
        }

        private void CrystalReportViewer1_Load(object sender, System.EventArgs e)
        {
            // CrystalReportTest is the report to export to text
            CrystalReportViewer1.ReportSource = new CrystalReportTest();

            // Export tool bar button is removed prorammatically
            // so that user's must use the programmed button.
            CrystalReportViewer1.ShowExportButton = true;
        }
    }
}



 
Old November 29th, 2007, 06:17 AM
Registered User
 
Join Date: Nov 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to shahzaduetian Send a message via Yahoo to shahzaduetian
Default

MANY DOT MATRIX PRINTERS HAVE TWO TO FOUR MODES. USERS WHO WANT TO QUICKLY RUN OFF DOCUMENTS WITHOUT WORRYING ABOUT PRINT QUALITY USE THE *DRAFT* MODE. FOR PRINTING EVEN FASTER AND ROUGHER, THERE'S A *HIGH SPEED DRAFT MODE*. WHEN PRINT QUALITY COUNTS, USERS SWITCH TO *REPORT-QUALITY* MODE AND, FINALLY, THERE IS *LETTER-QUALITY* MODE. IN LETTER-QUALITY MODE, YOUR DOT MATRIX PRINTER OPERATES MUCH SLOWER AS IT PRODUCES MORE DOTS FOR EACH CHARACTER






Similar Threads
Thread Thread Starter Forum Replies Last Post
Exporting Crystal Report To Excel mohithmohith VB.NET 1 July 12th, 2008 12:36 AM
Exporting Crystal Report Harinder.Dhamija ASP.NET 2.0 Professional 1 July 24th, 2007 02:45 AM
logon error while exporting crystal report hotshot_21 Crystal Reports 0 February 28th, 2006 07:37 AM
Exporting Crystal Report to PDF vishal.jayaswal .NET Web Services 0 December 30th, 2004 03:31 AM
headings requires while exporting crystal report suni_kutty Crystal Reports 0 November 26th, 2004 06:36 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.