Results 1 to 6 of 6

Thread: Best way to print a template

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2011
    Posts
    9

    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!
    Last edited by bobhaha; Mar 22nd, 2011 at 09:17 AM.

  2. #2
    PowerPoster cicatrix's Avatar
    Join Date
    Dec 2009
    Location
    Moscow, Russia
    Posts
    3,654

    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.

  3. #3

    Thread Starter
    New Member
    Join Date
    Mar 2011
    Posts
    9

    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?

  4. #4
    Frenzied Member
    Join Date
    Jan 2010
    Location
    Connecticut
    Posts
    1,687

    Re: Best way to print a template

    Welcome to VB Forums!!!

    To create the file just use Word. Click Save As html and you will have your html document.
    VB6 Library

    If I helped you then please help me and rate my post!
    If you solved your problem, then please mark the post resolved

  5. #5
    PowerPoster cicatrix's Avatar
    Join Date
    Dec 2009
    Location
    Moscow, Russia
    Posts
    3,654

    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:
    Code:
    <html>
    </html>
    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.

  6. #6

    Thread Starter
    New Member
    Join Date
    Mar 2011
    Posts
    9

    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?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width