Solved

Flexible Document Report Generation

Posted on 2004-04-22
6
193 Views
Last Modified: 2006-11-17
Hello,
We have a VB application that does contain some calculated data and also some employee records read in from a file....  we'd like to be able to generate customer documents from this information.  These documents will have a cover page, summary of personal data, nice images, year-by-year calculations and such.

It would be nice to be able to easily change the format of these reports... changing images, colors, adding company logos, rearranging or removing data points....  ideally this "document report" is an external file that we manipulate and into goes the data from Visual basic...

What are our options?  One thing we've thought of is maybe using Word templates and then VB would merge in data and print....
IF we need to generate 1000 reports to a printer... will that solution work or will it be too cumbersome and prone to crash.

We don't think hardcoding print statements in VB is the way to go.

We dont' know much about crystal reports but that might be an option.

Another option might be somehow using or creating PDF files and printing them to the hard drive for review prior to actual printing... possibly creating PDF templates where the data gets embedded.  is it possible to merge data from a VB app into a PDF template?  Anyone know?

We are very open to suggestions from experts.  Thank you for your time.
0
Comment
Question by:torrid333
  • 3
  • 2
6 Comments
 
LVL 28

Expert Comment

by:AzraSound
ID: 10889925
Word is a good option, and I dont think it would be any more prone to crash than any other method, given that you properly code it to release memory, etc.  Will all users have Word installed?  That is a requirement.

Print commands, definitely a no-no IMO because of the difficulty in creating this "template".

Crystal Reports is good, but altering the report template requires knowledge of Crystal Reports.  If that's no problem, I would definitely look into it.

PDF, never really worked with anything other than converting to them.  Not sure how easy it would be merge data into it.

Another options is to use an RTF document, which you can load in VB using the RichTextBox control.  You can have a template report file that can be edited in something like WordPad, or Word.  You could open the template to change logos, etc.  Data points might be handled by placing "keywords" in the document that you would run through and replace with actual data, e.g.,


-- Document:

Total for Year: [YearTotal]


In VB, after loading the document:

RichTextBox.Text = Replace$(RichTextBox.Text, "[YearTotal]", myCalculatedTotal)


There are more efficient ways of searching for certain strings and replacing them with the RichTextBox but that was just to give you an idea.
0
 

Author Comment

by:torrid333
ID: 10890861
How are images and colors handled in a Rich Text Format doc?  I supposed I should read up on it.... could user control from within our app the fonts/colors/etc. if we provided them access to it....  or is that done to the template outside the VB app using Word or Wordpad?

Also for the images... would you have to open the RTF doc in word etc. to replace the image?  Then save... then app can load into RTB control for printing????  

I suppose the RichTextBox would allow for fairly easy "print preview"????  

Also part of the document is multi-colum "data" which is hard to print using the replace fields method due to the number of numbers and the variation in number of columns and rows... unless maybe there is a way to take data from a grid... and plop it into the RTF at a tag that's like [GridData]...  is there a way to add that to the RTB control?  Right now alas we are stuck in print statement mode...
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 10890952
Images can be added dynamically via code.   Colors can be changed on the fly as you "print out" to the control.  Therefore, much customization could be handled through your application interface.

Print preview is relatively simple with the RichTextBox.  When you print from it, you simply specify a device context to send the information to, be it the Printer or a Picturebox.

There is no direct way to create column in the RichTextBox control.  The best method is to use a fixed width font (e.g., Courier New) and pad space as necessary.  For example, say you have defined a column to be 20 characters wide, you could do:

RichTextBox.SelText = MyData & String$(30 - Len(MyData), " ")

This will write our your data, and the necessary number of spaces to pad it to 30 characters.
0
 

Author Comment

by:torrid333
ID: 11255137
OK I will award points after one more related question to Azra.....

Is it possible to mix printing... i.e. print from Rich Text Box 1 then print some spreadsheet data using print  statements, then print from Rich Text Box 2?  i.e. have different templates frmo different pages?  Someone said that RTB  printing prints as one document and you can't do several in one printed document.  Is that true????  any thoughts?
0
 
LVL 28

Accepted Solution

by:
AzraSound earned 500 total points
ID: 11259650
Look at MS KB article Q146022.  You will see that it shows how to setup a richtextbox for WYSIWYG printing.  Within that routine it sends a simple Printer statement for a new page.  You can alter this function to send simple print statements as needed.  As far as multiple richtextbox control's, thats a bit tougher.  If they are on separate pages it may be simpler, but if you want to mix and match on the same page, that would take some effort.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

778 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question