Results 1 to 9 of 9

Thread: Print button

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Mar 2006
    Posts
    23

    Print button

    Hi, I want to create a button so that i can print a form out either to a file or a printer, is this possible? the form is to be used as a invoice. i am using vb6, please help
    regards

  2. #2

  3. #3
    Fanatic Member mateo107's Avatar
    Join Date
    Jan 2005
    Posts
    547

    Re: Print button

    welcome to the forums ukmam....

    if you do a search on the VB6 forum for "print" or "printing" you're sure to find a lot of resources to help you..... it's a seemingly overly-complicated thing to do in VB6.

    Good Luck!


    -Matthew-

  4. #4

    Re: Print button

    Or if you want to print it out in a different way to how the form looks then something like this:
    VB Code:
    1. Private Sub cmdPrint_Click()
    2. intResponse = MsgBox("Are you sure you want to print?", 4 + vbQuestion, "Print") 'Message box appears asking if you are sure you want to print
    3.  
    4. If (intResponse = 6) Then 'If the answer is Yes then
    5. Printer.FontSize = 20 'Font size is 20
    6. Printer.FontUnderline = True 'Font is underlined
    7. Printer.Font = "Arial" 'Font is Arial
    8. Printer.Print 'Prints a blank line
    9. Printer.Print Tab(1); "Customer Details" 'Prints Customer Details
    10. Printer.FontSize = 14 'Font size is 14
    11. Printer.FontUnderline = False 'Font is not underlined
    12. Printer.Print 'Prints blank line
    13. Printer.Print Tab(10); lblName.Caption '10 spaces and prints the caption of the Name label
    14. Printer.Print Tab(10); lblAddress1.Caption '10 spaces and prints the caption of the 1st address line
    15. Printer.Print Tab(10); lblAddress2.Caption '10 spaces and prints the caption of the 2nd address line
    16. Printer.Print Tab(10); lblPostcode.Caption '10 spaces and prints the postcode
    17. Printer.Print Tab(10); lblPhone.Caption '10 spaces and prints the phone number
    18. Reference = lblName.Caption 'The variable 'Reference' is lblname.Caption
    19. Reference2 = lblPostcode.Caption 'The variable 'Reference2' is lblPostcode.caption
    20. Reference3 = lblPhone.Caption 'The variable, 'Reference3' is lblPhone.Caption
    21. Printer.Print 'Prints a blank line
    22. Printer.EndDoc 'Ends printing
    23. End If 'Ends If Function
    24.  
    25. End Sub

    You get the idea...

  5. #5
    Fanatic Member eimroda's Avatar
    Join Date
    Jul 2000
    Location
    Philippines
    Posts
    642

    Re: Print button

    maybe this could help:
    VB Code:
    1. Private Sub cmdPrint_Click()
    2.     Dim rs As New ADODB.Recordset
    3.  
    4.     Set rs.ActiveConnection = Nothing
    5.     rs.CursorLocation = adUseClient
    6.     rs.LockType = adLockOptimistic
    7.     rs.CursorType = adOpenStatic
    8.    
    9.    
    10.     rs.Fields.Append "myName", adChar, 30
    11.     rs.Fields.Append "myGender", adChar, 10
    12.     rs.Open
    13.     rs.AddNew
    14.    
    15.     rs.Fields("myName") = Text1
    16.     rs.Fields("myGender") = Combo1
    17.    
    18.     rs.Update
    19.  
    20.     Set dr.DataSource = rs
    21.     dr.Sections(3).Controls("txtName").DataField = "myName"
    22.     dr.Sections(3).Controls("txtGender").DataField = "myGEnder"
    23.     dr.Show
    24.    
    25.     Set rs = Nothing
    26. End Sub
    just an idea how you could use the datareport without a database ( if in case u dont have one)
    the data in my example came from a textbox and a combobox painted in a form... maybe you can modify it..
    On Error GoTo Hell

    Hell:
    Kill Me


    Food For Thought:

    - Do not judge a book... if you're not a judge!


  6. #6

    Thread Starter
    Junior Member
    Join Date
    Mar 2006
    Posts
    23

    Re: Print button

    Hi, thanks for quick reply, i have created a software where the user can select information on one listbox(form1, which gets a menu information from the database) and it passes to the form2(form that i want to print) so when i select a item on the list box in form 1, the information is passed to form 2. for example i click on item 6, item 6 information is put into a list box in form 2. then i like to create a button so i can print form 2 out, for example like a print screen of form 2? i am using database microsoft access.
    regards

  7. #7
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: print button

    Something like
    VB Code:
    1. 'on Form1
    2.  
    3. Private Sub List1_Click()
    4. Form2.List1.AddItem List1.List(List1.ListIndex)
    5. Form2.Show
    6. End Sub
    7.  
    8. 'on Form2
    9. Private Sub Form_Load()
    10. Me.PrintForm
    11. End Sub

  8. #8
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: print button

    Quote Originally Posted by ukmam via PM
    Hi, u recently gave me the me.printform to try out on my program, but i dialog appears and it says printing... but then an error pops up saying run time error "482" Printer error? is this because my printer isnt set up? thanks
    Probably. It is difficult to tell without knowing your setup. Do you have a printer installed on your machine?

    Also, there are three reasons why you shouldn't ask a question in a PM/Email:

    1. You are restricting yourself to only one person in terms of a possible answer. If you keep your questions on the open forum, all sorts of people will view it, and someone else may have something to contribute.

    2. Someone else could be having the same problem, and could benefit by what happens in your question post.

    3. In days and weeks to come, someone may have the same issue, and do a forum search to see if the question has been asked before, and if so, what was the answer. If everything is confined to a PM/Email, they won't find anything.


  9. #9

    Thread Starter
    Junior Member
    Join Date
    Mar 2006
    Posts
    23

    Re: Print button

    ok, in future i shall reply in the forums.

    There is a printer installed however the form doesnt print out, it says it printing but then wait a couple of minutes then it says its failed, is this because of what the format is, for example does it view it as a image format? regards

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