ADO Recordset Export Class
by Hussain Mohd. Elius
www.elvista.cjb.net
Make your recordset universal! Use this class to export whatever recordset into the industrial standered [csv], commercial standered [html] and the power user standered [Excel]. This is an updated version of my previous work, now complete Events, Properties, Documentation and even more options! Fuly optimized and commented. All bugs fixed. A must have for any database devoloper and a must add to any code library.
Licence Agreement:
Redistribution of this code (ADO
Recordset Export Class by Hussain Mohd. Elius), whole or in part, as source code
or in binary form, alone or as part of a larger distribution or product, is
forbidden for any commercial or for profit use without the author's explicit
permission. (written or through electronic mail)
Redistribution of this code, as source code or in binary form, with or without
modification, is permitted provided that the following conditions are met:
Redistributions of source code must include this list of conditions, and the
following acknowledgment:
The ADO Recordset Export Class Module was developed by Hussain Mohd. Elius. The
source code, written in Visual Basic, is freely available for non-commercial,
non-profit use at www.elvista.cjb.net
Redistributions in binary form, as part of a larger project, must include the
above acknowledgment in the end-user documentation. Alternatively, the above
acknowledgment may appear in the software itself, if and wherever such
third-party acknowledgments normally appear.
DOCUMENTATION
Declaration
In the General Declaration section type:
Private WithEvents export as DatabaseExport
Then in the Form_Load() Event or in any place but just before the class will be
used, type:
Set export = New DatabaseExport
Now use the Class as you wish. But remember to clear up this reference in the
Form_Unload() Event or anyplace after the use of the Class:
Set export = Nothing
Enumerated Constants (Enums)
DatabaseExportEnum
[CSV] = 0
[HTML] = 1
[Excel] = 2
The Properties
ProgressBar: Bind a progressbar to the class to show the progress of the
Export. Remarks: Error is generated if no progressbar is bound.
ADORecordset: Binds a recordset to the class. This is the class that will
be exported.
FilePath: This is the string to which the file will be exported. Error
Remarks: This one is optional for exporting in Excel.
The Methods
ExportToCSV: Exports the given recordsets to Comma Separated Values or
CSV. CSV can be read by almost any Database and Spreadsheet Program.
Remarks: If you have MSExcel, you can use it to open the CSV file and see the
difference between the CSV and the same recordset exported to Excel.
ExportToHTML: Exports the given recordset to HTML file so it can
easily be uploaded to the
internet or viewed from the intranet. Many options are in this method to make
customizability easier.
Remarks: You can use this Format to any platform, because all computers
nowadays have a browser. This will be the best option if you don't know your
client.
ExportToExcel: Exports the given recordset to Microsoft Excel. Excel
provides almost unlimited
control for the user over the recordset and you s/he can it to easily compute
or make graphs from the Excel.
Notes on usage: If you do not have Excel 10.0
originally used to write the program then simply remove reference from Excel
10.0 and select your version. If you do not have Excel at all, then simply do
not use the subroutines related to Excel.
Remarks: To use this method, the user must have MSExcel or Excel.exe An
advantage of exporting to Excel is that after this, the user can use Excel to
Export to other formats (from Save As.. Menu)
OpenRecordset: This method is not related to exporting. However this will
open a recordset from a database without much hastel and saves a few keystrokes.
The default options used to open the recordset is the fastest and recommended
when exporting.
Remarks: The Query Parameter must start with "WHERE "
ShowSave: Use this method and it's options to show a save as... Dialog
Box easily. This function is not really required to be used, however it is much
easier and reduces coding.
Returns: True if a file is saved. False if cancelled or if file path is null
string.
The Events
Event ExportError (Error As ErrObject)
Raised whenever an error is generated. use it to catch an error. To ignore
errors, just type Error.Clear
Event ExportStarted (ByVal ExportingFormat As DatabaseExportEnum)
Raised whenever Exporting Starts. This event is raised first, before any code is
executed.
Event ExportComplete (ByVal Success As Boolean, ByVal ExportingFormat As
DatabaseExportEnum)
Raised whenever exporting is completed. However, this is not called if an error
was NOT ignored. If an error was ignored Success returns False else True.
Please vote for this code. This may not be the best of its kind, but I am just a ninth grader. Your votes and feedback will encorage me to improve and present you with better programs in the years to come.
Documentation by Hussain Mohd. Elius (www.elvista.cjb.net)