Solved

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

Posted on 2004-10-16
9
493 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
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 Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

707 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now