Printable ListBox To Report Problem


I am using the code from Paul Lefebvre’s example of a “Printable List Box” (included in the example apps) so I can print in a report in multiple columns of basically the same date. The data is loaded from a recordset. The first 40 records are loaded into Column 0. The next 40 records are loaded into Column 2., etc… I use the code below to load the list box.

[code]Dim X as Integer
X = 0
Dim Row as Integer
Dim Col as integer


While Not rs.eof
X = X + 1

If X = 41 Then
  Elseif X = 81 Then
Elseif X = 121 Then
Elseif X = 161 Then
Elseif X = 201 Then
End If


List1.Cell(Row, Col)=txtMember.Text
Row=Row + 1


That works great in filling the list box with the correct data from the database.

I then use this code to print the contents of the List Box in a Report:

[code] Dim rpt As New ReportRoster
Dim rsq as new Reports.RecordSetQuery(rs)

//Adjusts Printer Resolution
dim ps as new printersetup
ps.MaxHorizontalResolution = 300
ps.MaxVerticalResolution = 300

Dim g As Graphics
g = OpenPrinterDialog(ps, Nil)
If g <> Nil Then
If rpt.Run(frmRosters.PrintableListBox, ps) Then
If rpt.Document <> Nil Then
End If
End If
End If[/code]

That will print correctly, but the problem is that I get an extra page for each column that is filled up with the Listbox. So if the Listbox has 3 columns, I get three pages that want to print. The first page is what it should look like, with the second two pages being blank.

I was wondering if there was a way (In Code) that I can tell the app just to print the first page, since there will never be enough data to print more than one page?

Any help would be greatly appreciated.

This executes for each record:


so you end up with a 200+ row listbox that is mostly empty.
You can stop adding rows after the first column is done.

If col = 0 then List1.AddRow

Hi John and Markus,

Thank you for taking the time to help. Your comments got me thinking that the code above was not the problem, but rather how the ListBox was being loaded.

For my Listbox, I wanted 40 rows displayed, and all the other rows deleted, so I just let the rows get added and then deleted the rows I did not need after. I used this code:

//Removes Extra Listbox Rows that were created. for i as integer=PrintableListbox.listcount-1 downto 40 PrintableListBox.removeRow(i) next

Thanks again for your help.