Final Thoughts

I’ve written enough code over time using the Printer object to decide that there has to be a better way. Fortunately, there are a couple. First, you can use the RichTextBox control to help format your text. This may not be a lot easier, but you may be able to build a series of small RichText documents that contain the proper formatting for your data, and then merge them together into one large RichText document to send to the printer. You can even save the report as a disk file by using the SaveFile method, so it could be included as an attachment in an e-mail message.

Another option is to create your own Word or Excel documents and use the native power of those applications to perform your formatting and printing. This is even more powerful than the RichText approach, since you can easily combine text and graphics into a single report.

Consider the case of a systems integrator who recommends a series of hardware and software services. It might be desirable to format a summary letter based on some key information from the recommendations, plus include charts and graphs that discuss the recommendations even further. The report would end with a list of recommended hardware and software with detailed pricing information. While you could do this yourself in Visual Basic, it screams Word and Excel. The only problem is that the data is in your database, and Word and Excel can’t read a database.

Of course, the option that most programmers will take, especially the lazy programmers working with databases, will be to use Crystal Reports or the new Microsoft Data Reporter. Both make it easy to create your own custom reports from the database with far less effort than any of the options discussed in this chapter. While the results may not be as nice as the custom reports you can write by hand or create using Word and Excel, the report writers provide a fast, easy way to build reports. They offer the ability to add more reports down the road, without requiring you to release a new version of the software.

No matter which way you look at it, you have a rich selection of tools to help you create your own custom documents and reports.

© 1998 SYBEX Inc. All rights reserved.