Results 1 to 6 of 6

Thread: Printing contents of Listbox

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jul 1999
    Posts
    5,923

    Post

    Hiya

    Anyone know how I can print the contents of a listbox line by line, nothing fancy, just plain text. I would like to have the Printer dialog come up as well if that is possible.

    Thank you!

  2. #2
    Guest
    Code:
    Private Sub Command1_Click()
    
        Dim iList As Integer
        Dim sList As String
        For iList = 0 to List1.ListCount - 1
            sList = sList & List1.List(iList) & vbCrLf
        Next iList
    
        If Msgbox("Would you like to print?", vbOKCancel) = vbOK Then
            Printer.Print sList
            Printer.EndDoc
        Else
            Msgbox "Printing canceled."
        End If
    
    End Sub

  3. #3
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    Code:
    Option Explicit
    '
    'API function to call the printer dialog box
    '
    Private Declare Function PrintDlg Lib "comdlg32.dll" _
    Alias "PrintDlgA" (pPrintdlg As PRINTDLGS) As Long
    
    Private Type PRINTDLGS
        lStructSize As Long
        hwndOwner As Long
        hDevMode As Long
        hDevNames As Long
        hDC As Long
        flags As Long
        nFromPage As Integer
        nToPage As Integer
        nMinPage As Integer
        nMaxPage As Integer
        nCopies As Integer
        hInstance As Long
        lCustData As Long
        lpfnPrintHook As Long
        lpfnSetupHook As Long
        lpPrintTemplateName As String
        lpSetupTemplateName As String
        hPrintTemplate As Long
        hSetupTemplate As Long
    End Type
    
    
    Private Sub Command1_Click()
    
    Dim PrintStruct As PRINTDLGS
    PrintStruct.lStructSize = Len(PrintStruct)
    Call PrintDlg(PrintStruct)
    
    With List1
        For i = 0 To .ListCount - 1
            Printer.Print List1.List(i)
        Next
    End With
    Printer.EndDoc 'start printer
    
    End Sub
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  4. #4

    Thread Starter
    PowerPoster
    Join Date
    Jul 1999
    Posts
    5,923

    Talking

    Thanks guys! Swift response...however HeSaidJoe, it just prints to the default printer, no matter which printer you select in the dialog!
    Last edited by chrisjk; Feb 2nd, 2001 at 09:09 PM.

  5. #5
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    Sorry, kicked out early and gone fishing all day.

    Try changing your command1 code to this...actually just added one new line but I only have one printer so I can't test it.

    Code:
    Private Sub Command1_Click()
    
    Dim PrintStruct As PRINTDLGS
    PrintStruct.lStructSize = Len(PrintStruct)
    Call PrintDlg(PrintStruct)
    
    Set Printer = Printer.DeviceName
    
    With List1
        For i = 0 To .ListCount - 1
            Printer.Print List1.List(i)
        Next
    End With
    Printer.EndDoc 'start printer
    
    End Sub
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  6. #6

    Thread Starter
    PowerPoster
    Join Date
    Jul 1999
    Posts
    5,923

    Caught anything big? :)

    Thanks ...Joe but I already tried that one and it either didn't make any difference, or just plan blew up...Object Required apparently.

    Doh!

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