更改 Microsoft Access 报表的组标题的可见性
我正在使用 Access 2010 创建多个报告,但我不知道如何隐藏组标题(如果其为空)。
想象一下,我有一个表格,例如(注意,我对汽车一无所知,这只是一个例子):
H1 | H2 | H3 | H4 | DATA1 | DATA2 | DATA3 car | chassis | engine | pistons | data_a1 | data_a2 | data_a3 car | chassis | engine | pistons | data_b1 | data_b2 | data_b3 car | chassis | engine | pistons | data_c1 | data_c2 | data_c3 car | chassis | engine | cylinder | data_a1 | data_a2 | data_a3 car | chassis | engine | cylinder | data_b1 | data_b2 | data_b3 car | interior | | seats | data_a1 | data_a2 | data_a3 car | interior | | seats | data_b1 | data_b2 | data_b3
我有 3 个按顺序排列的 H1、H2 和 H3 列的组标题。我遇到的问题是,当 H3 不包含文本(即“”(我认为访问将其评估为空))时,我想隐藏 H3 的组标题或至少使其不占用报告上的空间。目前,只要 H3 为空,报表仍包含空白行。
我已经在 GroupHeader3 的 Paint 和/或 Print 事件中尝试过这个和类似的
If IsNull([H3]) Then
Me.GroupHeader3.Height = 0
Me.GroupHeader3.BackColor = vbRed
Me.GroupHeader3.Visible = False
Else
Me.GroupHeader3.Height = 5
Me.GroupHeader3.BackColor = vbGreen
End If
想法似乎可行,也就是说,如果我注释掉 Visible=False 行,我会在正确的位置得到红色或绿色背景,但是它完全忽略了高度选项。 如果我将 Visible=False 放在上面,则会抱怨它无法放入 on Paint 事件中。
我也尝试在 GroupHeader2 的绘制事件中添加类似的代码,但没有成功。我得到的最接近的它只是坐在那里闪烁。
我对 vba 有点陌生,所以我可能会错过一些明显的东西,但目前我不太确定如何继续,所以任何帮助将不胜感激。
编辑 为了清楚起见:
该报告的布局有点像这样:
H1 H2 H3 H4 DATA1 DATA2 DATA3
因此,对于上面的示例数据,它会显示为:
car chassis engine pistons data_a1 data_a2 data_a3 data_b1 data_b2 data_b3 data_c1 data_c2 data_c3 cylinder data_a1 data_a2 data_a3 data_b1 data_b2 data_b3 interior seats data_a1 data_a2 data_a3 data_b1 data_b2 data_b3
它是我想要避免的内部和座位之间的空白行(组标题 3)。 谢谢
I'm using Access 2010 to create several reports and i can't figure out how to hide a group heading if its empty.
Imagine I have a table such as (n.b. i know nothing about cars, its just an example):
H1 | H2 | H3 | H4 | DATA1 | DATA2 | DATA3 car | chassis | engine | pistons | data_a1 | data_a2 | data_a3 car | chassis | engine | pistons | data_b1 | data_b2 | data_b3 car | chassis | engine | pistons | data_c1 | data_c2 | data_c3 car | chassis | engine | cylinder | data_a1 | data_a2 | data_a3 car | chassis | engine | cylinder | data_b1 | data_b2 | data_b3 car | interior | | seats | data_a1 | data_a2 | data_a3 car | interior | | seats | data_b1 | data_b2 | data_b3
I have got 3 group headers of columns H1,H2 and H3 in that order. The problem i have is, when H3 contains no text (i.e. "" (I think access evaluates that as null)) i want to hide the group header for H3 or at least make it so it takes no space on the report. Currently wherever H3 is blank, the report still contains a blank row.
I've tried this and similar in GroupHeader3's Paint and or Print events
If IsNull([H3]) Then
Me.GroupHeader3.Height = 0
Me.GroupHeader3.BackColor = vbRed
Me.GroupHeader3.Visible = False
Else
Me.GroupHeader3.Height = 5
Me.GroupHeader3.BackColor = vbGreen
End If
The idea seems to work, that is if i comment out the Visible=False line i get a red or a green background in the right places, however it completely ignores the height option.
If i put the Visible=False on it complains that it can't be put in the on Paint event.
I've also tried putting similar code in GroupHeader2's paint event but to no avail. The closest I've got it just sits there and flickers.
I'm kinda new to vba so i might be missing something obvious, but at the moment I'm not really sure how to proceed so any help would be much appreciated.
EDIT
For clarity:
The report is laid out a bit like so:
H1 H2 H3 H4 DATA1 DATA2 DATA3
So with the example data above it would appear as:
car chassis engine pistons data_a1 data_a2 data_a3 data_b1 data_b2 data_b3 data_c1 data_c2 data_c3 cylinder data_a1 data_a2 data_a3 data_b1 data_b2 data_b3 interior seats data_a1 data_a2 data_a3 data_b1 data_b2 data_b3
Its the blank line (group header 3) between interior and seats that i want to avoid.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您向我们显示的是列标题而不是组标题。如果其他标题仍然存在,那么更改 H3 的高度有什么意义呢?这样你无法节省空间。
也许您想通过将 H3 右侧的列向左移动 H3 的宽度来隐藏整个列 H3。没有简单的方法可以做到这一点。您必须计算所涉及的文本字段和标签的位置,并在 OnFormat 事件中相应地更改它们的“左”位置。
编辑:
使用组标题的Format事件过程的Cancel参数:
由于VBA代码永远不会在设计模式下运行,因此您只能在打印预览和打印时看到它的效果。
You are showing us column headers not group headers. What sense does it make to change the hight of H3 if the other headers are still here? You can't save space that way.
Probably you want to hide the whole column H3 by moving the columns at the right of H3 to the left by the width of H3. There is no easy way to do that. You will have to calculate the positions of the text fields and lables involved and change their "Left" position accordingly in a OnFormat event.
EDIT:
Use the Cancel parameter of the Format event procedure of the group headers:
Since the VBA code never runs in design mode, you will only see its effect in the print preview and when printing.
这是一篇较旧的帖子,但是先生。 Jacot-Decomes 的帖子帮助我弄清楚了 Access 中标头的一些条件格式。我在第一页之后需要一个不同的标题。
This is an older post, but Mr. Jacot-Descomes' post helped me figure out some conditional formatting for headers in Access. I needed a different header after the first page.