Results 1 to 5 of 5

Thread: How to print?

  1. #1

    Thread Starter
    Junior Member
    Join Date
    May 2000
    Posts
    19
    Let say i have a lot of records like e.g

    name age class sex
    mary 10 pri 5 f
    david 10 pri 5 m

    what are the commands to get all these records printed out and how to align them to look professional. Do you know how to preview before print also?

    Thank you for your help.
    God bless
    Nigel
    [email protected]

  2. #2
    Addicted Member curlywink's Avatar
    Join Date
    Mar 2000
    Location
    Manila, Philippines
    Posts
    141

    Talking

    Hi there,

    If you want to print eg.. records directly use the Printer object etc.. if u want it previewed, try using Crystal Reports (included w/ vb) ...


    Hope this helps ...

  3. #3
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238

    Smile Printer Object + TextBox Control will do.

    Hi nigel_chong88, all you need is...
    • 1 TextBox control
    • 1 CommandButton


    need not necessary must use Crystal Report.

    The code is just as simple as below:
    Code:
    Option Explicit
    Private Db As DAO.Database
    Private Rs As DAO.Recordset
    Private Sub Command1_Click()
    'Get the first printer from the system's printer list
    Dim xPrinter As Printer
    For Each xPrinter In Printers
        If IsObject(xPrinter) Then
            Set Printer = xPrinter
            Exit For
        End If
    Next
    Printer.Orientation = 1
    'Print the preview data into selected printer
    Printer.Print Text1
    Set Printer = Nothing
    End Sub
    
    Private Sub Form_Load()
        'Retrieve data from the Bibli.mdb on Authours Table
        'There is total 3 fields from this Table
        '1. Au_ID
        '2. Author
        '3. Year Born
        Set Db = DBEngine.Workspaces(0).OpenDatabase(App.Path & "\Biblio.mdb", False, False)
        Set Rs = Db.OpenRecordset("SELECT * FROM Authors WHERE Au_ID < 200;", dbOpenSnapshot)
        While Not Rs.EOF
            'Put all the records into the Text1 TextBox control for preview purpose.
            'For alignment, I used vbTab over here to seperate each type of records.
            'Note: For safty purpose, make sure you have set the TextBox Locked
            'properties to True, else the user will be free to change
            'the retrieved records.
            Text1 = Text1 & Rs.Fields(0) & vbTab & Rs.Fields(1) & vbTab & Rs.Fields(2) & vbCrLf
            Rs.MoveNext
        Wend
        Rs.Close
        Db.Close
        Set Rs = Nothing
        Set Db = Nothing
    End Sub

  4. #4
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367
    I agree with Chris, but you might not want to use vbTab if your strings are of varying lengths. You could try:

    Code:
    Text1 = Text1 & Rs.Fields(0) & space(20-len(rs.fields(0)) & Rs.Fields(1) & space(20-len(rs.fields(1)) & Rs.Fields(2) & vbCrLf
    This will help keep things lined up.

    This code works if you use a font like courier new.

  5. #5
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238

    Thumbs up

    Hi! Negative0, how come I can forget about this... By the thanks for your amendment.

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