• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 205
  • Last Modified:

Flexible Document Report Generation

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.
  • 3
  • 2
1 Solution
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.
torrid333Author Commented:
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...
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.
torrid333Author Commented:
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?
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.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now