Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Need advice on printing reports from Visual Basic

Need advice on printing reports from Visual Basic

Scheduled Pinned Locked Moved Visual Basic
visual-studiographicssysadmintutorial
19 Posts 3 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K kentuckyjoe

    Ben, hold on that request for a code snippet. I found an article and some code. The way I understand it, and will try it later, is to have a form and add to it a PrintDocument control to the form. Then I will have access to statements like the ones you gave to me. I'm looking forward to trying this out. Thanks. jack

    D Offline
    D Offline
    dg6yhw11
    wrote on last edited by
    #7

    I don't use a PrintDocument control either. Just the printer. Here's a complete sub we currently use Public Sub PrintMaintenanceRenewalLetters( _ rsIn As ADodb.Recordset, _ PayDOSCustomersIn() As String, _ DoingReminderIn As Boolean, _ Optional StartFromIn As Integer = 1, _ Optional Recs2Print As Integer = 9999, _ Optional CustNumberIn As String = "-X") Dim CustNoHold As String Dim LastLine As Single Dim iCtr As Integer Dim StateTablesBought As Integer Dim CDAdder As Currency Dim ExtPrice As Currency Dim ExtFreight As Currency Dim SalesTax As Currency Dim QtyBought As Long Dim BkMark As Variant ' Const FED_PART_NO As String = "87FEDST-03" ' Const FED_DESCRIPTION As String = "Tax Table Service Fed + 1 State" ' Const FED_PRICE As Currency = 45# ' Const OLD_FED_PART_NO As String = "87003-04" Const FREIGHT_CHARGE As Currency = 3.95 LastLine = Printer.Height - 1440 Dim Ctr As Integer Ctr = 0 CustNoHold = "" If StartFromIn > 1 Then Do If Trim(rsIn![Customer_Number]) <> CustNoHold Then CustNoHold = Trim(rsIn!Customer_Number) Ctr = Ctr + 1 End If rsIn.MoveNext Loop Until Ctr = StartFromIn rsIn.MoveNext CustNoHold = "" ElseIf CustNumberIn <> "-X" Then Do If Not rsIn.EOF Then rsIn.MoveNext If rsIn.EOF Then Exit Do End If Loop Until (Trim(rsIn![Customer_Number]) = CustNumberIn) Or rsIn.EOF If rsIn.EOF Then MsgBox "Customer Number " & CustNumberIn & " not found!", vbCritical + vbOKOnly, "Error" Exit Sub End If CustNoHold = "" End If Do Do If Trim(rsIn![Customer_Number]) <> CustNoHold Then If CustNoHold <> "" Then ' Print the CD adder Printer.FontBold = True Printer.ForeColor = vbRed Printer.Print Printer.CurrentX = DESCRIPTION_LEFT Printer.Print "____"; Printer.CurrentX = DESCRIPTION_LEFT + 450 Printer.Print "Please send my services on a CD" Printer.CurrentX = DESCRIPTION_LEFT + 450 Printer.Print "ins

    K 2 Replies Last reply
    0
    • D dg6yhw11

      I don't use a PrintDocument control either. Just the printer. Here's a complete sub we currently use Public Sub PrintMaintenanceRenewalLetters( _ rsIn As ADodb.Recordset, _ PayDOSCustomersIn() As String, _ DoingReminderIn As Boolean, _ Optional StartFromIn As Integer = 1, _ Optional Recs2Print As Integer = 9999, _ Optional CustNumberIn As String = "-X") Dim CustNoHold As String Dim LastLine As Single Dim iCtr As Integer Dim StateTablesBought As Integer Dim CDAdder As Currency Dim ExtPrice As Currency Dim ExtFreight As Currency Dim SalesTax As Currency Dim QtyBought As Long Dim BkMark As Variant ' Const FED_PART_NO As String = "87FEDST-03" ' Const FED_DESCRIPTION As String = "Tax Table Service Fed + 1 State" ' Const FED_PRICE As Currency = 45# ' Const OLD_FED_PART_NO As String = "87003-04" Const FREIGHT_CHARGE As Currency = 3.95 LastLine = Printer.Height - 1440 Dim Ctr As Integer Ctr = 0 CustNoHold = "" If StartFromIn > 1 Then Do If Trim(rsIn![Customer_Number]) <> CustNoHold Then CustNoHold = Trim(rsIn!Customer_Number) Ctr = Ctr + 1 End If rsIn.MoveNext Loop Until Ctr = StartFromIn rsIn.MoveNext CustNoHold = "" ElseIf CustNumberIn <> "-X" Then Do If Not rsIn.EOF Then rsIn.MoveNext If rsIn.EOF Then Exit Do End If Loop Until (Trim(rsIn![Customer_Number]) = CustNumberIn) Or rsIn.EOF If rsIn.EOF Then MsgBox "Customer Number " & CustNumberIn & " not found!", vbCritical + vbOKOnly, "Error" Exit Sub End If CustNoHold = "" End If Do Do If Trim(rsIn![Customer_Number]) <> CustNoHold Then If CustNoHold <> "" Then ' Print the CD adder Printer.FontBold = True Printer.ForeColor = vbRed Printer.Print Printer.CurrentX = DESCRIPTION_LEFT Printer.Print "____"; Printer.CurrentX = DESCRIPTION_LEFT + 450 Printer.Print "Please send my services on a CD" Printer.CurrentX = DESCRIPTION_LEFT + 450 Printer.Print "ins

      K Offline
      K Offline
      kentuckyjoe
      wrote on last edited by
      #8

      I'm sorry about that Ben thing. Murray, thanks much for this. I'm getting ready to try it in a few minutes. I have a feeling that VS 2010 does not like the printer. commands. I tried that before and got an error message. I think I may have to add the printDocument control. But I'll find out in just a few minutes. I'm going to take a form, add a button, and put your code into the button's click event. I'll comment out lines of code concering the recordset. If that doesn't work I may try the code in a subroutine inside of a module that I call. Anyway, I'm going to mess around with it and I'll let you know of progress, or lack thereof. Thank you Murray. Jack

      1 Reply Last reply
      0
      • D dg6yhw11

        I don't use a PrintDocument control either. Just the printer. Here's a complete sub we currently use Public Sub PrintMaintenanceRenewalLetters( _ rsIn As ADodb.Recordset, _ PayDOSCustomersIn() As String, _ DoingReminderIn As Boolean, _ Optional StartFromIn As Integer = 1, _ Optional Recs2Print As Integer = 9999, _ Optional CustNumberIn As String = "-X") Dim CustNoHold As String Dim LastLine As Single Dim iCtr As Integer Dim StateTablesBought As Integer Dim CDAdder As Currency Dim ExtPrice As Currency Dim ExtFreight As Currency Dim SalesTax As Currency Dim QtyBought As Long Dim BkMark As Variant ' Const FED_PART_NO As String = "87FEDST-03" ' Const FED_DESCRIPTION As String = "Tax Table Service Fed + 1 State" ' Const FED_PRICE As Currency = 45# ' Const OLD_FED_PART_NO As String = "87003-04" Const FREIGHT_CHARGE As Currency = 3.95 LastLine = Printer.Height - 1440 Dim Ctr As Integer Ctr = 0 CustNoHold = "" If StartFromIn > 1 Then Do If Trim(rsIn![Customer_Number]) <> CustNoHold Then CustNoHold = Trim(rsIn!Customer_Number) Ctr = Ctr + 1 End If rsIn.MoveNext Loop Until Ctr = StartFromIn rsIn.MoveNext CustNoHold = "" ElseIf CustNumberIn <> "-X" Then Do If Not rsIn.EOF Then rsIn.MoveNext If rsIn.EOF Then Exit Do End If Loop Until (Trim(rsIn![Customer_Number]) = CustNumberIn) Or rsIn.EOF If rsIn.EOF Then MsgBox "Customer Number " & CustNumberIn & " not found!", vbCritical + vbOKOnly, "Error" Exit Sub End If CustNoHold = "" End If Do Do If Trim(rsIn![Customer_Number]) <> CustNoHold Then If CustNoHold <> "" Then ' Print the CD adder Printer.FontBold = True Printer.ForeColor = vbRed Printer.Print Printer.CurrentX = DESCRIPTION_LEFT Printer.Print "____"; Printer.CurrentX = DESCRIPTION_LEFT + 450 Printer.Print "Please send my services on a CD" Printer.CurrentX = DESCRIPTION_LEFT + 450 Printer.Print "ins

        K Offline
        K Offline
        kentuckyjoe
        wrote on last edited by
        #9

        Murray, I put a form in my project, added a button, and put the following code behind it's click event.

        Public Class Form1
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Printer.FontBold = True
        printer.print("Hello World")
        Printer.Print()
        End Sub
        End Class

        It doesn't like the printer statements. It says it's undeclared. I must need a reference, an imports statement, or a declaration of some sort. Any ideas? jack

        D 1 Reply Last reply
        0
        • K kentuckyjoe

          Murray, I put a form in my project, added a button, and put the following code behind it's click event.

          Public Class Form1
          Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
          Printer.FontBold = True
          printer.print("Hello World")
          Printer.Print()
          End Sub
          End Class

          It doesn't like the printer statements. It says it's undeclared. I must need a reference, an imports statement, or a declaration of some sort. Any ideas? jack

          D Offline
          D Offline
          dg6yhw11
          wrote on last edited by
          #10

          As I hope I mentioned I am a VB6 expert who has assiduously avoided the .NET realm so far. (I manage 435,000 lines of code that I do not want to convert). Although that will have to change. I would have to assume that the printer object (if available) is defined in the System namespace. Did you try system.printer.print "Hello World" If that doesn't work then I'm sorry but I'm out of ideas.

          K 1 Reply Last reply
          0
          • D dg6yhw11

            As I hope I mentioned I am a VB6 expert who has assiduously avoided the .NET realm so far. (I manage 435,000 lines of code that I do not want to convert). Although that will have to change. I would have to assume that the printer object (if available) is defined in the System namespace. Did you try system.printer.print "Hello World" If that doesn't work then I'm sorry but I'm out of ideas.

            K Offline
            K Offline
            kentuckyjoe
            wrote on last edited by
            #11

            Thanks Murray. Unfortunately it did not work. It said printer was not a member of system. It's too bad it doesn't work as what you explained to me was something that I could understood and could work with. It is so simple; you want to print something you say 'print something'. Why they had to go and make things so much more complicated; I dunno. 435,000 lines of code; wow! I would not want your job. Good luck on it and when conversion time comes; good luck on that. Thanks for your help Murray. I'm going to keep working on this and if I learn anything interesting I'll let you know. Jack

            D 1 Reply Last reply
            0
            • K kentuckyjoe

              Thanks Murray. Unfortunately it did not work. It said printer was not a member of system. It's too bad it doesn't work as what you explained to me was something that I could understood and could work with. It is so simple; you want to print something you say 'print something'. Why they had to go and make things so much more complicated; I dunno. 435,000 lines of code; wow! I would not want your job. Good luck on it and when conversion time comes; good luck on that. Thanks for your help Murray. I'm going to keep working on this and if I learn anything interesting I'll let you know. Jack

              D Offline
              D Offline
              dg6yhw11
              wrote on last edited by
              #12

              Any time, Jack. You know there is another version of Basic that is procedural and hence much easier to use. It does have statements as easy as print something. I used it to produce 4 commercial products for 10 years. It is called PowerBasic. www.powerbasic.com I only stopped using it when I was forced to remake our products for Windows. It didn't have any GUI support at all in the beginning although it does now. It also has a huge user community with tons of free code. Happy Memorial Day.

              Murray

              K 1 Reply Last reply
              0
              • D dg6yhw11

                Any time, Jack. You know there is another version of Basic that is procedural and hence much easier to use. It does have statements as easy as print something. I used it to produce 4 commercial products for 10 years. It is called PowerBasic. www.powerbasic.com I only stopped using it when I was forced to remake our products for Windows. It didn't have any GUI support at all in the beginning although it does now. It also has a huge user community with tons of free code. Happy Memorial Day.

                Murray

                K Offline
                K Offline
                kentuckyjoe
                wrote on last edited by
                #13

                Murray, thanks for this info and I'll definitely check it out. I found a free e-book, see link below, on printing in VB 2010. I've read thru it and grabbed some code snippets and I think I'm going to be able to make it work for me. Sometime when you're feeling really masochistic you should check it out. Microsoft makes things much harder than they need to be. For example: Instead of print "sometext" it is e.graphics.drawstring("sometext") I really don't care what it is just as long as I know what it is and I can use it. And, I have tried the e.graphics.d... and it works. MS is using VB graphics for printing. Okay, I guess I can get accustomed to that. So, I'll stumble along this way and I'll also check out PowerTools. This is good to know. Thanks. Jack http://www.filemount.com/2011/01/printing-with-visual-basic-2010/

                D 1 Reply Last reply
                0
                • K kentuckyjoe

                  Murray, thanks for this info and I'll definitely check it out. I found a free e-book, see link below, on printing in VB 2010. I've read thru it and grabbed some code snippets and I think I'm going to be able to make it work for me. Sometime when you're feeling really masochistic you should check it out. Microsoft makes things much harder than they need to be. For example: Instead of print "sometext" it is e.graphics.drawstring("sometext") I really don't care what it is just as long as I know what it is and I can use it. And, I have tried the e.graphics.d... and it works. MS is using VB graphics for printing. Okay, I guess I can get accustomed to that. So, I'll stumble along this way and I'll also check out PowerTools. This is good to know. Thanks. Jack http://www.filemount.com/2011/01/printing-with-visual-basic-2010/

                  D Offline
                  D Offline
                  dg6yhw11
                  wrote on last edited by
                  #14

                  Hi Jack, Thanks for the link to the ebook. Actually the process is pretty much as I described for VB 6, just with a lot more typing. (When I was in school we used to say that COBOL was a horrible language to code in because of all the keyboarding involved. COBOL is a walk in the park compared to VB 10, even with intellisense.) My products do payroll everywhere there is a US payroll and other government forms so you can just imagine the amount of reports we have to print. The page you sent did have links to a couple of books you might find helpful.

                  Murray

                  K 1 Reply Last reply
                  0
                  • D dg6yhw11

                    Hi Jack, Thanks for the link to the ebook. Actually the process is pretty much as I described for VB 6, just with a lot more typing. (When I was in school we used to say that COBOL was a horrible language to code in because of all the keyboarding involved. COBOL is a walk in the park compared to VB 10, even with intellisense.) My products do payroll everywhere there is a US payroll and other government forms so you can just imagine the amount of reports we have to print. The page you sent did have links to a couple of books you might find helpful.

                    Murray

                    K Offline
                    K Offline
                    kentuckyjoe
                    wrote on last edited by
                    #15

                    Hi Murray, I'm beginning to like this printing capability. I'm not very good at it yet but I do see the potential for good reports. It takes a lot of code and but most of it is understandable. Crystal Reports is an attempt to greatly simplify things. And although this sounds crazy they've made it so damn simple I can't understand it. I just have so much trouble with CR. With this language you can use simple VB constructs like 'if then else' and in CR they do have 'if then else' but it's really different. I would rather spend 3 days working on one report than even 10 minutes with CR. I know that after spending 3 days with VB I would have something; 3 days with CR and all I would end up with is a huge headache. Someday I'm afraid you're gonna have to upgrade from VB 6. I hope not though. No one would want to do all the conversion work on your codebase. Here's a business opportunity. Write a program to do just the report conversions. I say 'just' as if this would be trivial; it certainly would not be. But, if you, or one of your co-workers could do it it would be worth something. Maybe it's already been done; I don't know. That's fabulous that your products do work for the government. That is HUGE!! If a company could have only one customer that is the one they should want; the US Govt. This is very impressive. I'm a retired Fed. I was a software developer there for 30 years. I worked on administrative systems to include accounting systems. I had co-workers that worked on payroll although I never did. I know some of the complexities though and I know there are many. Keep the faith Murray. I'm gonna get back to work on these reports. In this methodology one has to line breaks, page breaks, etc. I like detail work though so I'm a happy camper. Thanks Murray and happy Wed. to you. jack

                    D 1 Reply Last reply
                    0
                    • K kentuckyjoe

                      Hi Murray, I'm beginning to like this printing capability. I'm not very good at it yet but I do see the potential for good reports. It takes a lot of code and but most of it is understandable. Crystal Reports is an attempt to greatly simplify things. And although this sounds crazy they've made it so damn simple I can't understand it. I just have so much trouble with CR. With this language you can use simple VB constructs like 'if then else' and in CR they do have 'if then else' but it's really different. I would rather spend 3 days working on one report than even 10 minutes with CR. I know that after spending 3 days with VB I would have something; 3 days with CR and all I would end up with is a huge headache. Someday I'm afraid you're gonna have to upgrade from VB 6. I hope not though. No one would want to do all the conversion work on your codebase. Here's a business opportunity. Write a program to do just the report conversions. I say 'just' as if this would be trivial; it certainly would not be. But, if you, or one of your co-workers could do it it would be worth something. Maybe it's already been done; I don't know. That's fabulous that your products do work for the government. That is HUGE!! If a company could have only one customer that is the one they should want; the US Govt. This is very impressive. I'm a retired Fed. I was a software developer there for 30 years. I worked on administrative systems to include accounting systems. I had co-workers that worked on payroll although I never did. I know some of the complexities though and I know there are many. Keep the faith Murray. I'm gonna get back to work on these reports. In this methodology one has to line breaks, page breaks, etc. I like detail work though so I'm a happy camper. Thanks Murray and happy Wed. to you. jack

                      D Offline
                      D Offline
                      dg6yhw11
                      wrote on last edited by
                      #16

                      Hi Jack, You're so right about the detail work that it is capable of. I looked @ it some more and it is really nothing more than an extremely complicated version of what I use in VB 6. The abilities for placements, fonts, kerning, leading and so on are excellent. They do require attention to detail but, what non-trivial programming doesn't? Attention to detail is what separates the hacks from the professionals. What language did you code in?

                      Murray

                      K 1 Reply Last reply
                      0
                      • D dg6yhw11

                        Hi Jack, You're so right about the detail work that it is capable of. I looked @ it some more and it is really nothing more than an extremely complicated version of what I use in VB 6. The abilities for placements, fonts, kerning, leading and so on are excellent. They do require attention to detail but, what non-trivial programming doesn't? Attention to detail is what separates the hacks from the professionals. What language did you code in?

                        Murray

                        K Offline
                        K Offline
                        kentuckyjoe
                        wrote on last edited by
                        #17

                        Murray, I did some COBOL back in the day but the last 16 years of my career were spent with a product I'll bet you've never heard of. Not many have. It's Model 204. It has been around for 40 years and it is so powerful. It's a DBMS with it's own proprietary language. It's for mainframe IBM computers (if they still exist) with very large databases. It really hums. Here's a link. Spend a minute or so checking it out. http://sirius-software.com/m204.html[^]

                        D 1 Reply Last reply
                        0
                        • K kentuckyjoe

                          Murray, I did some COBOL back in the day but the last 16 years of my career were spent with a product I'll bet you've never heard of. Not many have. It's Model 204. It has been around for 40 years and it is so powerful. It's a DBMS with it's own proprietary language. It's for mainframe IBM computers (if they still exist) with very large databases. It really hums. Here's a link. Spend a minute or so checking it out. http://sirius-software.com/m204.html[^]

                          D Offline
                          D Offline
                          dg6yhw11
                          wrote on last edited by
                          #18

                          You're right - I've never heard of it. I used COBOL and FORTRAN on IBM mainframes. Then again I've never worked on government-scale databases. No wonder my friends who code for the IRS moan when Congress enacts a payroll change and gives us 30 days to implement it. I must assume that mainframes still exist although I saw a Cray supercomputer in a box about the size of a PC only twice as wide. Microsoft was offering it as a prize.

                          Murray

                          K 1 Reply Last reply
                          0
                          • D dg6yhw11

                            You're right - I've never heard of it. I used COBOL and FORTRAN on IBM mainframes. Then again I've never worked on government-scale databases. No wonder my friends who code for the IRS moan when Congress enacts a payroll change and gives us 30 days to implement it. I must assume that mainframes still exist although I saw a Cray supercomputer in a box about the size of a PC only twice as wide. Microsoft was offering it as a prize.

                            Murray

                            K Offline
                            K Offline
                            kentuckyjoe
                            wrote on last edited by
                            #19

                            It's been long years since I've even heard of a Cray computer. I wonder if they still exist. At one time they were considered top of the line. And yes, you could probably put in a box of Cracker Jacks now. It would fit. Happy Thur Murray. jack

                            1 Reply Last reply
                            0
                            Reply
                            • Reply as topic
                            Log in to reply
                            • Oldest to Newest
                            • Newest to Oldest
                            • Most Votes


                            • Login

                            • Don't have an account? Register

                            • Login or register to search.
                            • First post
                              Last post
                            0
                            • Categories
                            • Recent
                            • Tags
                            • Popular
                            • World
                            • Users
                            • Groups