Problem with code to draw lines for blank fields

M

Michael

Hello everyone,

I need to be able to have 28 text boxes, rectangles, etc.... anything that
will make between 1 and 28 rectangles so that if I have less than 28 checks
there will still be 28 boxes (i.e. 2 checks = 26 blank text boxes, 4 checks
= 24 blank text boxes, etc...).

Duane gave me this code:

Private Sub Report_Page()
Dim intNumLines As Integer
Dim intLineNumber As Integer
Dim intTopMargin As Integer
Dim ctl As Control
Dim intLineHeight As Integer
Dim intLineLeft As Integer
Dim intLineWidth As Integer
intNumLines = 26
intLineLeft = 720 '1/2 inch from left margin
intLineWidth = 1440 * 5 '5 inches
intTopMargin = Me.Section(3).Height
intLineHeight = Me.Section(0).Height
Me.FontSize = 14
For intLineNumber = 0 To intNumLines - 1
Me.CurrentX = intLineLeft
Me.CurrentY = intTopMargin + _
(intLineNumber * intLineHeight)
Me.Print intLineNumber + 1
Me.Line (intLineLeft, intTopMargin + _
(intLineNumber * intLineHeight)) _
-Step(intLineWidth, 0)
Next
End Sub

But it gives me an error when I use it.

Error title Microsoft Visual Basic

Run-time error '6':

Overflow.

Maybe I'm applying the code at the wrong place.

Any help? You out there Duane
 
M

Marshall Barton

Michael said:
I need to be able to have 28 text boxes, rectangles, etc.... anything that
will make between 1 and 28 rectangles so that if I have less than 28 checks
there will still be 28 boxes (i.e. 2 checks = 26 blank text boxes, 4 checks
= 24 blank text boxes, etc...).

Duane gave me this code:

Private Sub Report_Page()
Dim intNumLines As Integer
Dim intLineNumber As Integer
Dim intTopMargin As Integer
Dim ctl As Control
Dim intLineHeight As Integer
Dim intLineLeft As Integer
Dim intLineWidth As Integer
intNumLines = 26
intLineLeft = 720 '1/2 inch from left margin
intLineWidth = 1440 * 5 '5 inches
intTopMargin = Me.Section(3).Height
intLineHeight = Me.Section(0).Height
Me.FontSize = 14
For intLineNumber = 0 To intNumLines - 1
Me.CurrentX = intLineLeft
Me.CurrentY = intTopMargin + _
(intLineNumber * intLineHeight)
Me.Print intLineNumber + 1
Me.Line (intLineLeft, intTopMargin + _
(intLineNumber * intLineHeight)) _
-Step(intLineWidth, 0)
Next
End Sub

But it gives me an error when I use it.

Error title Microsoft Visual Basic

Run-time error '6':

Overflow.


Are you sure the detail section is not too tall to display
26 times on one page.

You should use Long instead of integer just in case a line
is drawn more than 11 inches from the top of the page.
 
M

Michael

It definitely has enough room because if there are more checks (up to 26)
they fit but when there's only 1 check it doesn't display the boxes I need.

I put in rectangles but even though they are of the same size as the field I
cannot get them to perfectly match up.
 
M

Marshall Barton

I have no idea what you mean by "I put in rectangles but
even though they are of the same size as the field I cannot
get them to perfectly match up", but that probably was a
waste of time, so it doesn't matter.

I still think the overflow error is caused by using Integer
instead of Long. Otherwise, Duane's code looks good to me.

There is one refinement that may help in your case. Add a
text box (named txtDetails) to the report (or group) Header
section and set it's control source to the expression
=Count(*)
Then modify the code to only draw the required number of
rectangles:
intNumLines = 28 - Me.txtDetails
 

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