Printing Tables from visual basic please important for school

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • desertsolider
    New Member
    • Jan 2007
    • 18

    Printing Tables from visual basic please important for school

    Is there any code to print all the records in table from visual basic and with out using any wizards please its very important for my project
    thanks
  • hariharanmca
    Top Contributor
    • Dec 2006
    • 1977

    #2
    Originally posted by desertsolider
    Is there any code to print all the records in table from visual basic and with out using any wizards please its very important for my project
    thanks

    Could you be more specific?

    Comment

    • desertsolider
      New Member
      • Jan 2007
      • 18

      #3
      Originally posted by hariharanmca
      Could you be more specific?
      Ok i have an access database which contains tables lets say contains:
      security table & Customers table .....
      and i want to print the security table all the fields in it ,
      thats the best i can explain and thx for replying

      Comment

      • Killer42
        Recognized Expert Expert
        • Oct 2006
        • 8429

        #4
        Originally posted by desertsolider
        Ok i have an access database which contains tables lets say contains:
        security table & Customers table .....
        and i want to print the security table all the fields in it ,
        thats the best i can explain and thx for replying
        Do you have any code to read the table? Just read through the table and for each of the records, use the Printer object to print all the fields you're interested in.

        I'm assuming you're using VB6. Please let us know whether this is correct.

        Comment

        • desertsolider
          New Member
          • Jan 2007
          • 18

          #5
          Originally posted by Killer42
          Do you have any code to read the table? Just read through the table and for each of the records, use the Printer object to print all the fields you're interested in.

          I'm assuming you're using VB6. Please let us know whether this is correct.
          oh sorry yes iam using vb6 and my skill isnt this high . and i dun kno what u meant but is this going to print all the table ?
          thanks

          Comment

          • sukeshchand
            New Member
            • Jan 2007
            • 88

            #6
            Try this code you should connect the printer on lpt1 to get the printout

            Code:
            Dim rs As New ADODB.Recordset
            Open "Lpt1:" For Output As #1
            rs.Open "Select * from Table1", conn, adOpenForwardOnly, adLockReadOnly
            Do While Not rs.EOF
                For i = 0 To rs.Fields.Count - 1
                    Print #1, rs.Fields(i).Value & ""
                Next i
                rs.MoveNext
            Loop
            rs.Close
            Close #1

            Comment

            • Killer42
              Recognized Expert Expert
              • Oct 2006
              • 8429

              #7
              Originally posted by sukeshchand
              Try this code you should connect the printer on lpt1 to get the printout...
              Thanks for the sample. However, it would be a better idea generally to use the Printer object rather than writing directly to LPT1.

              Comment

              • sukeshchand
                New Member
                • Jan 2007
                • 88

                #8
                Tell me how to use printer object

                is it like this

                Code:
                for ----- 
                Printer.Print rs.fields(i)
                next ---
                and finally 
                printer.EndDoc

                Comment

                • Killer42
                  Recognized Expert Expert
                  • Oct 2006
                  • 8429

                  #9
                  Originally posted by sukeshchand
                  ...is it like this
                  Code:
                  for ----- 
                    Printer.Print rs.fields(i)
                  next ---
                  and finally 
                  printer.EndDoc
                  Yes. But the Print statement, and other features of the Printer object, also allow you to do much more. You can position things and format things in all sorts of ways.

                  For example, a slight enhancement to your code...
                  Code:
                  for ----- 
                    Printer.Print rs.fields(i).Name; " : "; rs.fields(i).Value
                  next ---
                  I'd recommend that you read up on the Printer object in the documentation, for more info.

                  Comment

                  • desertsolider
                    New Member
                    • Jan 2007
                    • 18

                    #10
                    sorry i couldnt connect to the internet i got a proplem...... Thanks for the codes i will try and thankss again

                    Comment

                    Working...