Best way to print a template
Hey guys, first post here!
I have been working on a inventory management system for a friend of mine. It has to be able to keep track of incoming and outgoing stock from his business.
I have already got all the programing done, working great! But now it has got to the stage, that I need the program to print out invoices from the program. I have the program extract certain records from an attached database, and will most probably pass them into a variable in the function.
NOW... I have a template of the tax invoice page setup in MS word. I was going to make a macro in word that will automatically fill in all the "static" information, but I was wondering if passing the variables from the main program into the word macro is: 1. possible and 2. the best way of doing this.
I am still a noob when it comes to VB so please excuse the next question, but is there a way to set up a page to be printed including tables, logo, different font styles.. etc within the VB program?
If at all possible I want to stay clear of the MS word idea, but is that the easiest way of doing this?
Thanks in advance!
Re: Best way to print a template
By referencing Microsoft.Office.Word.Interop.dll (Office Interop Assemblies) you can do from from your code anything you can do in VBA environment, so the answer to the first question is yes, it's possible.
As for the second question, I found it quite convenient to use HTML for such purposes. Referencing MS Word would render you dependent on the Office version while generation of a HTML file even from scratch is not very difficult. You can load it into a web browser control to provide a print preview functionality and print it from there. Moreover, your reports will be platform independent and one would be able to open them in any web browser working under any operating system.
Re: Best way to print a template
Ah great, a few google searches found me some HTML controls, but nothing very concrete. Would you happen to have a link to some controls or an example? Specifically the creation of the file, and connection to the file. Is it similar to the way you connect to a access DB file?
Thanks for the post!
PS: I have done a little reading, and others are suggesting to use a RTF files. Any thoughts?
Re: Best way to print a template
Welcome to VB Forums!!! :wave:
To create the file just use Word. Click Save As html and you will have your html document.
Re: Best way to print a template
A HTML file is a simple text file which uses HTML syntax.
The simplest HTML file will look like this:
A little bit more advanced one (you can copy/paste the following code into a new html file and open it in any web browser to see the results).
Code:
<html>
<head>
<title>A sample HTML file</html>
</head>
<body>
<h1>Hello, there</h1>
<table>
<tr><td>Column1</td><td>Column2</td></tr>
<tr><td>Value1</td><td>Value2</td></tr>
</table>
</body>
</html>
Now, open a file using FileStream class, use StreamWriter to write the above code and close the file.
Re: Best way to print a template
OMG how stupid of me!
Sorry my mind was stuck in C++, where you would create a file by opening it in a directory.
I have just had a glass of water and my mind refreshed.... I have now created a template of the invoice in dreamweaver and I am going to use that HTML code in my program, which will allow me to place the order variables in the correct table slots etc... This is actually an extremely easy way to solve this problem.
So as well as editing the records in the database, it will be able to retrieve the invoice information from a local folder, which I will save all the HTML files to. This way I will not need to worry about muti related tables within the database.
Thoughts?