?
Solved

Printing Contents of a Frame etc. using visual basic 6.

Posted on 2004-10-16
9
Medium Priority
?
612 Views
Last Modified: 2013-11-25
Hello, i am making a program that requirs to print a sort of invoice thing you could call it.  and i need to print out the invoice.  I have all the details in seperat lables all on one frame and was how you print the frame or/and the contents of the frame if it is even possible.  Or is there a better way of printing, i dont know much about printing with visual basic so any suggestions would be greatly appersiated.

Thanx

Gary
0
Comment
Question by:Gary_4500
  • 4
  • 2
7 Comments
 
LVL 12

Accepted Solution

by:
Bob Lamberson earned 80 total points
ID: 12330903
Hi Gary_4500,
Since you will eventually want to include data with your invoice, you would be better off creating the invoice as a DataReport.
Right click on the project in the Project Explorer and select DataReport and it will add a template for you to work from, which will allow you to programmatically add data and print the report.

Bob
0
 

Author Comment

by:Gary_4500
ID: 12333110
Yeah but i have no idea how data reports work or even where to start with them?
0
 
LVL 12

Expert Comment

by:Bob Lamberson
ID: 12333305
> Right click on the project in the Project Explorer and select DataReport
> and it will add a template for you to work from
Check the help file and if you have specific questions, post them.
Bob
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Gary_4500
ID: 12333439
I can add it and all that, but when i run it it says invalid data source.  i looked on the  microsoft web site and it says you have to add all this data enviroment (which i dont have or cant find).  and i cant look at the help files cause i dont have the msdn disc.
0
 
LVL 12

Expert Comment

by:Bob Lamberson
ID: 12334565
Gary_4500,
You will need the OCT2001 MSDN file to be able to access the vb6 help files. You will need this as you are learning how to use vb. I was unable to find a download source for the file and I would recommend that you post a question asking if anyone knows a source for that file.
Bob
0
 
LVL 16

Expert Comment

by:jimbobmcgee
ID: 12345955
Printing an invoice really simply would just require invoking the PrintForm method of an invoice form:

     frmInvoice.Printform

but it's by far the prettiest.

Last time i needed to print an invoice, I outputted it to a text file, using some HTML formatting I knew, and printed it from a browser control, e.g.:

     Type Item
              Number as Long
              Name as String
              Quantity as Integer
              UnitPrice as Currency
     End Type

     Dim arrItems(1 To 5) as Item
     Dim curSubtotal as Currency
     Dim sngTax as Single

     sngTax = 0.175             '<--- UK SALES TAX/VAT MULTIPLIER (17.5%)

     Open App.Path & "\Invoices\" & lngInvoiceNo & ".htm" for Output as #1

              Print #1, "<HTML>"
              Print #1, "<HEAD><TITLE>Invoice #" & lngInvoiceNo & "</TITLE></HEAD>"
              Print #1, "<BODY>"
              Print #1, "<TABLE>
              Print #1, "<TR><TD>Customer Name:</TD><TD>" & strCustomerName & "</TD></TR>"
              Print #1, "<TR><TD>Customer Address:</TD><TD>" & strCustomerAddress1 & "<BR>" & _
                                                                                                 strCustomerAddress2 & "<BR>" & _
                                                                                                 strCustomerTown & "<BR> & _
                                                                                                 strCustomerCounty & "<BR> & _
                                                                                                 strCustomerPostCode & "</TD></TR>
              '...YOUR HEADER FIELDS
             
              Print #1, "</TABLE>"
              Print #1, "<HR>"
              Print #1, "<TABLE>"
              Print #1, "<TR><TD>No</TD><TD>Desc</TD><TD>Unit</TD><TD>Qty</TD><TD>Total</TD></TR>
             
              For i = LBound(arrItems) to UBound(arrItems)

                    Print #1, "<TR><TD>" & arrItems(i).Number & "</TD>" & _
                                          "<TD>" & arrItems(i).Name & "</TD>" & _
                                          "<TD>" & arrItems(i).UnitPrice & "</TD>" & _
                                          "<TD>" & arrItems(i).Quantity & "</TD> " & _
                                          "<TD>" & arrItems(i).Quantity * arrItems(i).UnitPrice & "</TD></TR>"

                    curSubtotal = curSubtotal + (arrItems(i).Quantity * arrItems(i).UnitPrice)

              Next i

              Print #1, "<TR><TD colspan=4>Subtotal:</TD><TD>" & curSubtotal & "</TD></TR>"
              Print #1, "<TR><TD colspan=4>Tax:</TD><TD>" & curSubtotal * sngTax & "</TD></TR>"
              Print #1, "<TR><TD colspan=4>Total:</TD<TD>" & curSubtotal+(curSubtotal*sngTax) & "</TD></TR>"

              Print #1, "</TABLE>"
              Print #1, "</BODY>"
              Print #1, "</HTML>"

      Close #1

      WebBrowser1.Navigate(App.Path & "\Invoices\" & lngInvoiceNo & ".htm")
                                                                                'SHOW THE GENERATED INVOICE
     
      WebBrowser1.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER, 0, 0
                                                                                'PRINT THE CONTENTS OF THE BROWSER OBJECT

You'd have to change the variables, etc, to match your data, but this was the simplest method I found (so long as you know a little HTML).

HTH

J.
0
 
LVL 12

Expert Comment

by:Bob Lamberson
ID: 12529674
Gary - did you get your question answered or is there anything we can help with?
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

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

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

864 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