Printing a variable length array

S

Stuart

I would like to print a 1 dimensional array, which
contains simple text. The size of the array is
potentially very large, so putting it all into a single
label will not work. Any suggestions?
 
D

Duane Hookom

You can use code in the report like
For i = 1 to UBound(arYourArray)
Me.CurrentX = 500
Me.CurrentY = i * 400
Me.Print arYourArray(i)
Next
 
S

Stuart

Thanks very much, it works! I appreciate the
suggestions, as there is no help topic in Access2002 VBA
for the print method.

Stuart
 
S

Stuart

I should say it sort of works. Two problems have come up.
1. I get an overflow after about 80 lines.
2. I don't know how to advance the page. Everything
prints on page 1....

Thanks, Stuart
 
D

Duane Hookom

You may need to bind your report to some table with multiple records. It is
hard to answer unless the number of pages or some number of records can be
determined. The easiest method would be to place the array into a table and
then binding the report to the table.
 
S

Stuart

OK, I thought that might be the case. MS Access is
rather data oriented. This sort of thing would have been
very simple in COBOL or C, but c'est la vie.

Thanks for your help, Stuart
 
M

Marshall Barton

Stuart said:
I would like to print a 1 dimensional array, which
contains simple text. The size of the array is
potentially very large, so putting it all into a single
label will not work. Any suggestions?

As long as you're not trying to use sorting and grouping,
let's try an unbound report for this. Add a textbox to the
detail section and make the section only as tall as the text
box.

The logic to control this kind of report is to initialize
the array (or a recordset) in the report's Open event using
module level declarations.


Dim thearray(xx) As whatever
Dim lngLoopCounter As Long

Sub Report_Open(
' initialize the array values and sort them if needed
. . .
lngLoopCounter = 0
End Sub

Sub Detail_Format(
Me.textbox = thearray(lngLoopCounter)
lngLoopCounter = lngLoopCounter + 1
If lngLoopCounter <= UBound(thearray)
Me.NextRecord = False
End If
End Sub

If there's any cleanup to do, do it in the report's Close
event.
 
S

Stuart

Hey, it works!!!
Much thanks.

One small modification, it needed to be in the OnPrint,
not the OnFormat section.

And one small shortcoming, pages thinks there is one
page, so page counter says "page 1 of 1, page 2 of 1,
etc."

Thanks again, Stuart
 
M

Marshall Barton

Stuart said:
Hey, it works!!!
Much thanks.

One small modification, it needed to be in the OnPrint,
not the OnFormat section.

And one small shortcoming, pages thinks there is one
page, so page counter says "page 1 of 1, page 2 of 1,
etc."

That's weird! I went and tried it and everything worked
fine using the Format event, until I added a text box with
=Pages. I must not have ever done that before!?

I guess using Pages in an unbound report just doesn't work
particularly well ;-(
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top