border fill up code in subreport does not work

M

Masoud

hello,
im my report there is a subreport, my subreport shows records, for some
times that my records in subreport are less part of page will be white, i
want to fill up rest of subreport by border, i have used the code like below
but it does not work for subreport and just work for report.
thanks in advanced.

Private Sub Report_Page()
Dim intNumLines As Integer
Dim intLineNumber As Integer
Dim intTopMargin As Integer
Dim ctl As Control
Dim intLineHeight As Integer

intNumLines = 15
'height of page header
intTopMargin = Me.Section(3).Height
'height of detail section
intLineHeight = Me.Section(0).Height
For Each ctl In Me.Section(0).Controls
For intLineNumber = 0 To intNumLines - 1
Me.Line (ctl.Left, intTopMargin + _
(intLineNumber * intLineHeight)) _
-Step(ctl.Width, intLineHeight), , B
Next
Next
End Sub
 
M

Marshall Barton

Masoud said:
im my report there is a subreport, my subreport shows records, for some
times that my records in subreport are less part of page will be white, i
want to fill up rest of subreport by border, i have used the code like below
but it does not work for subreport and just work for report.
thanks in advanced.

Private Sub Report_Page()
Dim intNumLines As Integer
Dim intLineNumber As Integer
Dim intTopMargin As Integer
Dim ctl As Control
Dim intLineHeight As Integer

intNumLines = 15
'height of page header
intTopMargin = Me.Section(3).Height
'height of detail section
intLineHeight = Me.Section(0).Height
For Each ctl In Me.Section(0).Controls
For intLineNumber = 0 To intNumLines - 1
Me.Line (ctl.Left, intTopMargin + _
(intLineNumber * intLineHeight)) _
-Step(ctl.Width, intLineHeight), , B
Next
Next
End Sub

Because the main report is "in charge" of page related
actions, a subreport's Page event is not used.

You can use code in the Format event of the subreport's
detail section to set the position of the first row of
borders/rectangles into a main report text box (named
txtTopMargin):
Parent.txtTopMargin = Me.Top + Me.Section(0).Height

I think the main report's Page event procedure will then
look something like this air code:

Dim Hgt As Long, Y As Long
With Me.subreportcontrol.Report
Hgt = .Section(0).Height
For Y = Me.txtTopMargin To <paper height> -
- <bottom margin> - Me.Section(4).Height _
STEP lngHgt
For Each ctl In .Controls
Me.Line (ctl.Left, Y) - Step(ctl.Width, Hgt), , B
Next ctl
Next Y
End With
 
M

Masoud

thank you marshal, your code must be works but i don't know why does not work
and i have compile error for Me.subreportcontrol.Report, is it possible you
make your code more complete.

Thanks in advanced.
 
M

Marshall Barton

That code is just air code to explain the kind of logic you
need. It can not work until you change it to your
situation.

To be more precise, I would need to know the names/values
that you need to replace (subreport control name, name of
the text box you added to the main report and bottom
margin/paper height). I would also have to see a Copy/Paste
of the code you actually used.

I noticed that my air code had at least a couple of typing
errors. They should have been:

For Y = Me.txtTopMargin To <paper height> _
. . .
STEP Hgt
--
Marsh
MVP [MS Access]

thank you marshal, your code must be works but i don't know why does not work
and i have compile error for Me.subreportcontrol.Report, is it possible you
make your code more complete.

Marshall Barton said:
Masoud said:
im my report there is a subreport, my subreport shows records, for some
times that my records in subreport are less part of page will be white, i
want to fill up rest of subreport by border,
[snip]

Because the main report is "in charge" of page related
actions, a subreport's Page event is not used.

You can use code in the Format event of the subreport's
detail section to set the position of the first row of
borders/rectangles into a main report text box (named
txtTopMargin):
Parent.txtTopMargin = Me.Top + Me.Section(0).Height

I think the main report's Page event procedure will then
look something like this air code:

Dim Hgt As Long, Y As Long
With Me.subreportcontrol.Report
Hgt = .Section(0).Height
For Y = Me.txtTopMargin To <paper height> -
- <bottom margin> - Me.Section(4).Height _
STEP lngHgt
For Each ctl In .Controls
Me.Line (ctl.Left, Y) - Step(ctl.Width, Hgt), , B
Next ctl
Next Y
End With
 
M

Masoud

Thank you marshal,
My subreport control name is: rptsubTranstoConDoc
name of the text box: Me.txtTopMargin
paper height: 11.7" (A4 paper))
bottom margin: 0.8"
page header: 1.2917"
level 1 header: 1.2708"
level 1 footer: 0.9583"
Me.Section(0).Height(subform)=360
Me.top (subform)=4*360<4 records>
Me.txtTopMargin:(4*360<4 records>+360 (sub report header=360)+
Me.Section(0).Height(subform detail height)


Private Sub Report_Page()
Dim Hgt As Long, Y As Long
Dim ctl As Control

With Me.rptsubTranstoConDoc.Report
Hgt = .Section(0).Height
For Y = Me.txtTopMargin+ level 1 header+ page header To paper height -
level 1 footer -Me.Section(4).Height _
Step Hgt
For Each ctl In .Controls
Me.Line (ctl.Left, Y)-Step(ctl.Width, Hgt), , B
Next ctl
Next Y
End With


End Sub

I don't know exactly how and where I have to use and replace
subreportcontrol and my error (run time error 2455) is in this line:
With Me.rptsubTranstoConDoc.Report


Marshall Barton said:
That code is just air code to explain the kind of logic you
need. It can not work until you change it to your
situation.

To be more precise, I would need to know the names/values
that you need to replace (subreport control name, name of
the text box you added to the main report and bottom
margin/paper height). I would also have to see a Copy/Paste
of the code you actually used.

I noticed that my air code had at least a couple of typing
errors. They should have been:

For Y = Me.txtTopMargin To <paper height> _
. . .
STEP Hgt
--
Marsh
MVP [MS Access]

thank you marshal, your code must be works but i don't know why does not work
and i have compile error for Me.subreportcontrol.Report, is it possible you
make your code more complete.

Marshall Barton said:
Masoud wrote:
im my report there is a subreport, my subreport shows records, for some
times that my records in subreport are less part of page will be white, i
want to fill up rest of subreport by border, [snip]

Because the main report is "in charge" of page related
actions, a subreport's Page event is not used.

You can use code in the Format event of the subreport's
detail section to set the position of the first row of
borders/rectangles into a main report text box (named
txtTopMargin):
Parent.txtTopMargin = Me.Top + Me.Section(0).Height

I think the main report's Page event procedure will then
look something like this air code:

Dim Hgt As Long, Y As Long
With Me.subreportcontrol.Report
Hgt = .Section(0).Height
For Y = Me.txtTopMargin To <paper height> -
- <bottom margin> - Me.Section(4).Height _
STEP lngHgt
For Each ctl In .Controls
Me.Line (ctl.Left, Y) - Step(ctl.Width, Hgt), , B
Next ctl
Next Y
End With
 
M

Marshall Barton

Masoud said:
Thank you marshal,
My subreport control name is: rptsubTranstoConDoc
name of the text box: Me.txtTopMargin
paper height: 11.7" (A4 paper))
bottom margin: 0.8"
page header: 1.2917"
level 1 header: 1.2708"
level 1 footer: 0.9583"
Me.Section(0).Height(subform)=360
Me.top (subform)=4*360<4 records>
Me.txtTopMargin:(4*360<4 records>+360 (sub report header=360)+
Me.Section(0).Height(subform detail height)


Private Sub Report_Page()
Dim Hgt As Long, Y As Long
Dim ctl As Control

With Me.rptsubTranstoConDoc.Report
Hgt = .Section(0).Height
For Y = Me.txtTopMargin+ level 1 header+ page header To paper height -
level 1 footer -Me.Section(4).Height _
Step Hgt
For Each ctl In .Controls
Me.Line (ctl.Left, Y)-Step(ctl.Width, Hgt), , B
Next ctl
Next Y
End With


End Sub

I don't know exactly how and where I have to use and replace
subreportcontrol and my error (run time error 2455) is in this line:
With Me.rptsubTranstoConDoc.Report


The subreport **control** name is only used in the With
statement. Just make sure that is the name of the control
on the main report, which may be different from the name of
the report object that is displayed in the subreport
control.

I think(?) maybe this should help:

For Y = Me.txtTopMargin To 11.7 * 1440 - .9583 * 1440
- Me.Section(4).Height _
 
M

Masoud

Just for more information, my subreport there is in detail section of main
report, and I put the code you had sent to me before in print event of main
report instead of page event, now border fill up works for the first page of
each category (my main report has category) and there is no error with
subcontrol name, and it is ok for me.if you know the reason please send to
me, any way your code was help full to me.
Thank you so much.
 
M

Marshall Barton

I do not understand what you are trying to say about the
first page of a category.

The code I posted is supposed to draw the borders from the
last detail on each page down to the page footer section.
What are you seeing that makes it appear to be doing
something else?
 
M

Masoud

Hello, you are completely right because my coding in print event did not work
correctly, so I put my code in page event again, and I opened the report by
one bottom in the form that has string filter
DoCmd.OpenReport "rptTranstoCon", acViewPreview, , strFilter
It opens the report without error in with statement (invalid reference),
actually before I opened the report (completely) directly from data base
window and there was error.
1-I do not know this is normal or no?

2-border fill up works in this condition but from the too much down, My
report has group header and group footer, page header, so I added
me.section(3).height+ me.section(5).height+bottom margine to Me.txtTopMargin
I mean
For Y = Me.txtTopMargin+ me.section(3).height+ me.section(5).height+bottom
margine To …….
But does not work correctly and border start from downer than of my last
record and there is space?

3-in group header I have also another subreport that some times have recrds
(2 or 3 records)
So height of that will in depending of records in that.(it does not need
border fill up) but I think it effect on margin of border fill up in another
subreport .how I have to mention this control in my calculation.



Marshall Barton said:
I do not understand what you are trying to say about the
first page of a category.

The code I posted is supposed to draw the borders from the
last detail on each page down to the page footer section.
What are you seeing that makes it appear to be doing
something else?
--
Marsh
MVP [MS Access]

Just for more information, my subreport there is in detail section of main
report, and I put the code you had sent to me before in print event of main
report instead of page event, now border fill up works for the first page of
each category (my main report has category) and there is no error with
subcontrol name, and it is ok for me.if you know the reason please send to
me, any way your code was help full to me.
 
M

Marshall Barton

There is no way you can use the page event to put the
borders before the group footer.

It's going to look a little strange to have the group footer
section before the borders, but I think this should do
that:

For Y = Me.txtTopMargin + Me.Section(3).Height _
+ Me.Section(5).Height _
To 11.7 * 1440 - .8 * 1440 - Me.Section(4).Height _
STEP lngHgt

If you must have the borders before the group footer, then
it's going to require an entirely different approach using
the NextRecord property in the detail section's Format
event.
 
M

Masoud

Hello,
My problem about borders, seems solved but for some cases that my report is
in 2 pages and first page is full of records (contain all records) my group
footer moved to next page, while next page is blank and there is just my page
header and group footer.(no border)

Regading your previouse answer, you are right, I want borders before group
footer, is it possible explain more about NextRecord property in the detail
section's Format
event.


Thanks in advance.


Marshall Barton said:
There is no way you can use the page event to put the
borders before the group footer.

It's going to look a little strange to have the group footer
section before the borders, but I think this should do
that:

For Y = Me.txtTopMargin + Me.Section(3).Height _
+ Me.Section(5).Height _
To 11.7 * 1440 - .8 * 1440 - Me.Section(4).Height _
STEP lngHgt

If you must have the borders before the group footer, then
it's going to require an entirely different approach using
the NextRecord property in the detail section's Format
event.
--
Marsh
MVP [MS Access]

Hello, you are completely right because my coding in print event did not work
correctly, so I put my code in page event again, and I opened the report by
one bottom in the form that has string filter
DoCmd.OpenReport "rptTranstoCon", acViewPreview, , strFilter
It opens the report without error in with statement (invalid reference),
actually before I opened the report (completely) directly from data base
window and there was error.
1-I do not know this is normal or no?

2-border fill up works in this condition but from the too much down, My
report has group header and group footer, page header, so I added
me.section(3).height+ me.section(5).height+bottom margine to Me.txtTopMargin
I mean
For Y = Me.txtTopMargin+ me.section(3).height+ me.section(5).height+bottom
margine To …….
But does not work correctly and border start from downer than of my last
record and there is space?

3-in group header I have also another subreport that some times have recrds
(2 or 3 records)
So height of that will in depending of records in that.(it does not need
border fill up) but I think it effect on margin of border fill up in another
subreport .how I have to mention this control in my calculation.
 
M

Marshall Barton

Masoud said:
My problem about borders, seems solved but for some cases that my report is
in 2 pages and first page is full of records (contain all records) my group
footer moved to next page, while next page is blank and there is just my page
header and group footer.(no border)

Regading your previouse answer, you are right, I want borders before group
footer, is it possible explain more about NextRecord property in the detail
section's Format
event.


I give up. After spending way too much time on this, I have
not been able to make anything do what you want for a
subreport.
 

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