vba MS Access 在可以增长的细节部分周围画线

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2608718/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 11:31:46  来源:igfitidea点击:

MS Access Draw line around detail section that can grow

vbams-access

提问by Icode4food

This really shouldn't be hard, I just can't figure out how to do it.

这真的不应该很难,我只是不知道该怎么做。

I am making a proposal report that needs to have a border around it. The problem is to get the vertical lines on the side. I can't figure out how to get a line to grow and shrink based on the height of the detail section.

我正在制作一份需要有边框的提案报告。问题是要获得侧面的垂直线。我不知道如何根据细节部分的高度来增加和收缩一条线。

I have used Crystal reports and sure wish Microsoft would learn a few things in regards to MS Access report writing!

我使用过 Crystal 报表,当然希望 Microsoft 能在 MS Access 报表编写方面学到一些东西!

I am very comfortable with VBA so have no fears there.

我对 VBA 很满意,所以不用担心。

回答by dwo

You were right, this isn't so hard. The trick is to use 2 variables, top and bottom. In the PageHeader_Format event you set top to Me.Height, and in the PageFooter_Format event you set the bottom to Me.Top - correction, where correction is a fixed amound you use to fix the right length. I′m not sure where this amount comes from, you just have to try a little bit.

你是对的,这并不难。诀窍是使用 2 个变量,顶部和底部。在 PageHeader_Format 事件中,您将顶部设置为Me.Height,在 PageFooter_Format 事件中,您将底部设置为Me.Top - correction,其中校正是用于固定正确长度的固定量。我不确定这个金额是从哪里来的,你只需要尝试一下。

In the Report_Page event you can then draw your line from top to bottom.

在 Report_Page 事件中,您可以从上到下绘制线条。

回答by David-W-Fenton

Another method that nobody has mentioned is the one using the Line method of the report, outlined in Knowledge Base article 210321. I've used this one for years, and it can be used to draw both lines and rectangles. It's quite handy for invoices that have variable height subreports for the invoice details, but need the vertical lines to change according to the height of the main report detail.

另一种没有人提到的方法是使用报告的 Line 方法,在知识库文章 210321 中进行了概述。我已经使用这个多年了,它可以用来绘制线条和矩形。对于发票明细具有可变高度子报表但需要垂直线根据主报表明细的高度进行更改的发票来说非常方便。

回答by seawooluf

use the page event coupled with me.line and scaleheight / scalewidth. I draw a box around the whole page with the following. Play with it and see where you end up. It is very handy for making professional reports. If you want a line in a certain place on a report you can use the controls coordinates. like

使用页面事件加上 me.line 和 scaleheight / scalewidth。我在整个页面周围绘制了一个框,如下所示。玩它,看看你最终在哪里。制作专业报告非常方便。如果您想在报表的某个位置添加一条线,您可以使用控件坐标。喜欢

me.line(Mycontrol.left,mycontrol.top) - (myothercontrol.left+myothercontrol.width, myother control.top + myothercontrol.height)

Private Sub Report_Page()

Me.Line (0, 0)-(scalewidth -30, scaleheight-30), 0, B

End Sub

回答by PowerUser

No VBA needed.

不需要VBA。

  1. Make a dummy grouping that is unique to each detail. For that grouping, set footer to yes.
  2. In your new group footer section that you just created, add your line.
  3. In your detail section, select all the relevant fields that can grow and set Can Grow = Yes
  4. Done!
  1. 制作一个对每个细节都独一无二的虚拟分组。对于该分组,将页脚设置为是。
  2. 在您刚刚创建的新组页脚部分中,添加您的行。
  3. 在您的详细信息部分,选择所有可以增长的相关字段并设置Can Grow = Yes
  4. 完毕!

Edit

编辑

Off-topic, I agree that Access Reports could learn a lesson or two from Crystal. But Crystal isn't perfect either. [/flamewar]

题外话,我同意 Access Reports 可以从 Crystal 学到一两个教训。但水晶也不是完美的。[/火焰战]

回答by Kevin Ross

Try this one.

试试这个。

Right click on the detail bar and select properties. Set the special effect to “Sunken”. This will put kind of a border around the detail section that resizes with the detail section.

右键单击详细信息栏并选择属性。将特殊效果设置为“沉没”。这将在细节部分周围放置一个边框,随着细节部分调整大小。

I have tried to get a line to dynamically resize but its catch 22, by the time you know the height of the section (In the On Print event) you cant make any changes!

我试图让一条线动态调整大小,但它捕获 22,当您知道该部分的高度时(在 On Print 事件中),您无法进行任何更改!