Solved

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

Posted on 2004-10-16
9
529 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
9 Comments
 
LVL 12

Accepted Solution

by:
BobLamberson earned 20 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:BobLamberson
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
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 

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:BobLamberson
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:BobLamberson
ID: 12529674
Gary - did you get your question answered or is there anything we can help with?
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Suggested Solutions

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

733 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