vba 访问报告“Can Grow”属性需要影响相邻控件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8099208/
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 14:26:52  来源:igfitidea点击:

Access report "Can Grow" property needs to effect neighboring controls

ms-accessvbatextboxaccess-vbareport

提问by misterManager

I have a report with a bunch of controls in the Detail section. I am working off a word document that was given to me as a sample and I recreated it in access almost perfectly. What I need now is a way to handle overflowing the text boxes. I have "Can Grow" enabled, but here is the real issue:

我在“详细信息”部分有一个包含一堆控件的报告。我正在处理一份作为样本提供给我的 word 文档,我几乎完美地在 access 中重新创建了它。我现在需要的是一种处理溢出文本框的方法。我启用了“可以成长”,但这是真正的问题:

I have a fake table going on. Multiple text boxes arranged in a way that just doesn't work in a subform. Certain cells have red, green or yellow backgrounds while others are just plain white. When one of the text fields overflows, and "grows", the other text boxes in the same row stay the same size as before and it looks very very odd (703 twips vs 300). I would really just love for it to work as if it were a table in word/excel and the entire row would grow at once (all =703 twips), but seeing as how it isn't literally a "row" I just want a way to associate the height of these text boxes with each other.

我有一张假桌子。多个文本框以一种在子表单中不起作用的方式排列。某些单元格具有红色、绿色或黄色背景,而其他单元格只是纯白色。当其中一个文本字段溢出并“增长”时,同一行中的其他文本框保持与以前相同的大小,并且看起来非常奇怪(703 缇对 300)。我真的很喜欢它的工作方式,就好像它是 word/excel 中的表格一样,并且整行都会立即增长(全部 =703 缇),但看看它实际上不是我想要的“行”一种将这些文本框的高度相互关联的方法。

Is anything like this possible? If I need to clarify anything just let me know, I hope I've given ample information.

这样的事情有可能吗?如果我需要澄清任何事情,请告诉我,我希望我提供了足够的信息。

采纳答案by misterManager

Ok here we go. So I had a fake table, I needed it to have table borders around each text box and when one text box got taller than the others in the row, the borders would look totally wrong. So, what we have to do is literally draw on the report at runtime, which can be done in any view including print preview. This code must be placed in the Print event

好的,我们开始。所以我有一个假表格,我需要它在每个文本框周围都有表格边框,当一个文本框比行中的其他文本框高时,边框看起来完全错误。所以,我们要做的就是在运行时绘制报告,这可以在任何视图中完成,包括打印预览。此代码必须放在 Print 事件中

'step one. find out which box in the row has the greatest height value. 
'You can come across this information however you want. 
'It will likely depend on what data goes in the boxes.
'For the sake of the answer length we will skip that actual code

'step two. Take measurements and store them in variables.
'You will need a start point, and an end point in standard (x1,y1),(x2,y2) form.
Dim t As Integer 'top
Dim l As Integer 'left
Dim b As Integer 'bottom

'step three. Use these measurements and draw your lines.
'Try to use looping if your naming and report layout work will allow it.
Me.Line (l, t)-(l, b), RGB(0, 0, 0)
'       (x1,y1)(x2,y2),pick a color
'We just drew a line straight down the length of the control
'If you plan ahead, and place a line on the report permanently on top of the first row
'and below every row, you will only need to draw vertical lines.
'The lines below each row will be pushed down by the tallest control

I hope this helps. I had no idea this stuff existed before at all. Here is the MSDN info about it: http://msdn.microsoft.com/en-us/library/aa221362%28v=office.11%29.aspx

我希望这有帮助。我以前根本不知道这个东西存在。这是关于它的 MSDN 信息:http: //msdn.microsoft.com/en-us/library/aa221362%28v=office.11​​%29.aspx

回答by MrP

In the design view of your report select all the textbox controls in the detail section and all the labels in the page header section. Right click on one of the textbox controls and select Layout-> Tabular. The controls and labels should now align with each other.

在报表的设计视图中,选择详细信息部分中的所有文本框控件和页眉部分中的所有标签。右键单击文本框控件之一并选择Layout-> Tabular。控件和标签现在应该彼此对齐。

You've not set which version of Access you're using but this works in Access 2007.

您尚未设置您使用的 Access 版本,但这适用于 Access 2007。

回答by CJames

OK...

好的...

1 - Go into Design view of your report

1 - 进入报表的设计视图

2 - Select ALL the textbox controls in the detail section that you want to be table like and ALL grow if any one grows.

2 - 选择详细信息部分中您想要像表格一样的所有文本框控件,如果有任何增长,则全部增长。

3 - Right click on one of the selected textbox controls and select Layout -> Tabular.... but... now... after you have your textbox row controls as a tabular layout... You must do one thing more...

3 - 右键单击​​选定的文本框控件之一,然后选择布局 -> 表格...但是...现在...在您将文本框行控件作为表格布局之后...您必须再做一件事。 ..

4 - Inside your reports FORMAT TAB properties... Set ALL PADDING properties to 0.00... 0.00 for Top Padding, 0.00 Right Padding, 0.00 Left Padding and 0.00 Bottom Padding. (default is usually around 0.0208)

4 -在您的报告格式选项卡属性中...将所有填充属性设置为 0.00... 0.00 顶部填充、0.00 右侧填充、0.00 左侧填充和 0.00 底部填充。(默认值通常在 0.0208 左右)

5 - Please note that changing your textboxes to a Tabular Layout kinda throws your textboxes to the right (at least for me) so you may need to re-adjust them so they are aligned with your Page Header textboxes again (if you have any that you might be using to header name your table like columns).

5 - 请注意,将您的文本框更改为表格布局会使您的文本框向右抛出(至少对我而言),因此您可能需要重新调整它们,以便它们再次与您的页眉文本框对齐(如果您有任何您可能正在使用标题命名您的表格,如列)。

6 - Make sure ALL SPACE is removed in the detail area by having the bottom bar (page or report footer) snugly up against the bottom of your Tabular Textbox Layout and also ditto with the upper detail bar (page or report header).

6 - 通过将底部栏(页面或报告页脚)紧贴表格文本框布局的底部并与上部详细信息栏(页面或报告标题)相同,确保在详细信息区域中删除所有空间。

7 - Now when you look your report in print preview with max 200% or more zoom you WILL still see very very minor spaces between your cells in your layout but when you actually printthey will be almost unnoticeable unless you take out a magnifying lens.

7 - 现在,当您以最大 200% 或更大的缩放比例查看打印预览中的报告时,您仍然会看到布局中单元格之间的非常小的空间,但是当您实际打印时,除非您取出放大镜,否则它们几乎不会被注意到。

回答by Otto

I found a solution for my situation but I would like to have a better one... In my case, a TextBox at the left side is describing the content of 1 to 3 pictures on the right side. The TextBox, if enlarging more than the height of the first picture, would shift pictures 2 and 3 down, in spite of a properly designed Top-Attribute in the picture controls.

我找到了适合我的情况的解决方案,但我希望有一个更好的解决方案......就我而言,左侧的 TextBox 描述了右侧 1 到 3 张图片的内容。尽管在图片控件中设计了正确的 Top-Attribute,但如果 TextBox 放大到超过第一张图片的高度,则会将图片 2 和 3 向下移动。

My solution: I put the height attribute of the text box to 15cm (e.g 2 Inch) and enable it as shrinkable. However, strange, but this helps for positioning the Pictures at its desired Top-Locations... :-) as well as minimizing the horizontal space used.

我的解决方案:我将文本框的高度属性设置为 15 厘米(例如 2 英寸)并将其启用为可收缩。然而,奇怪的是,这有助于将图片定位在其所需的顶部位置...... :-) 以及最小化使用的水平空间。