How print the contents of a list box?

How print the contents of a list box?

Anonymous
Not applicable
404 Views
2 Replies
Message 1 of 3

How print the contents of a list box?

Anonymous
Not applicable
I've written a bit of code that goes off and does a search and then shows the results in a list box, but i'd also like to be able to print it out. Using the common dialog box control from comdlg32.ocx, i've ended up with the following, which i based on a VB6 program that used a rich text box:
Private Sub cmd_print_Click()
On Error Resume Next
With CommonDialog1
.CancelError = True
.DialogTitle = "Print Seach Results"
.PrinterDefault = True
.flags = cdlPDHidePrintToFile Or cdlPDNoPageNums Or cdlPDReturnDC
.flags = .flags Or cdlPDNoSelection
.ShowPrinter
If Err = 0 Then
' Print the entire contents of the text box
printer.Print lst_result.Text
End If
End With
End Sub

I end up with the print dialog showing OK, but nothing comes out. The rich text box program also had same format for printing, only it was printer.print richtextbox.text.
What do i need to do to get the contents printing out?

TIA.
0 Likes
405 Views
2 Replies
Replies (2)
Message 2 of 3

Anonymous
Not applicable
Maybe printer.enddoc

 

You might need to loop through the list box
ie

 

for i = 0 to me.lstBx.listcount-1

 printer.print me.lstBx.list(i)

next i

printer.enddoc

 

HTH

 

Chris


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
I've
written a bit of code that goes off and does a search and then shows the
results in a list box, but i'd also like to be able to print it out. Using the
common dialog box control from comdlg32.ocx, i've ended up with the following,
which i based on a VB6 program that used a rich text box:
Private Sub
cmd_print_Click()
        On Error
Resume Next
    With CommonDialog1

        .CancelError = True

        .DialogTitle = "Print
Seach Results"

        .PrinterDefault = True

        .flags =
cdlPDHidePrintToFile Or cdlPDNoPageNums Or cdlPDReturnDC

        .flags = .flags Or
cdlPDNoSelection

        .ShowPrinter

        If Err = 0 Then

                '
Print the entire contents of the text box

                printer.Print
lst_result.Text
        End If

    End With
End Sub

I end up with the print dialog showing OK, but nothing comes out. The rich
text box program also had same format for printing, only it was printer.print
richtextbox.text.
What do i need to do to get the contents printing out?

TIA.

0 Likes
Message 3 of 3

Anonymous
Not applicable
Found out why it won't work. The printer object doesn't exist in VBA, only in VB, so i have to use word or some other program instead to print through.
0 Likes