动态调整报表详细信息区域的大小

发布于 2024-11-26 22:21:44 字数 706 浏览 1 评论 0原文

是否可以在 MS Access 中动态调整报告的详细信息区域的大小?

我有一个报告,详细信息区域有 2 行,我希望其中一行是“可选”的 - 当没有数据时,它不应显示,并且详细信息区域应该只与最上面一行数据一样高。

我有这样的代码:

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
    Dim reduceHeight As Integer
    reduceHeight = Me.Label83.Height


    If IsNull(Me.data_1) Then
        Me.data_1.Visible = False
        Me.Label83.Visible = False
    Else
        Me.data_1.Visible = True
        Me.Label83.Visible = True
    End If

    If IsNull(Me.data_1) 
        Detail.Height = Detail.Height - reduceHeight
    End If

End Sub

它可以使标签和文本框有条件地可见,但当隐藏底线时我无法让详细信息区域缩小。我确实将详细信息的CanShrink属性设置为True,但它没有缩小。

Is it possible to resize the Detail area of a report dynamically, in MS Access?

I have a report and the Detail region has 2 rows, I'd like one of them to be "optional" - when there is no data it should not display and the Detail region should only be as tall as the top row of data.

I have code like this:

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
    Dim reduceHeight As Integer
    reduceHeight = Me.Label83.Height


    If IsNull(Me.data_1) Then
        Me.data_1.Visible = False
        Me.Label83.Visible = False
    Else
        Me.data_1.Visible = True
        Me.Label83.Visible = True
    End If

    If IsNull(Me.data_1) 
        Detail.Height = Detail.Height - reduceHeight
    End If

End Sub

And it works as far as makign the label and text box conditionally visible, but I can't get the Detail region to shrink when the bottom line is hidden. I did set the CanShrink property for the Detail to True, but it doesn't shrink.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

暖伴 2024-12-03 22:21:44

也为您的控件(例如文本框)设置CanShrink

在此处输入图像描述
在此处输入图像描述

Set CanShrink for your controls too (e.g. textboxes):

enter image description here
enter image description here

烈酒灼喉 2024-12-03 22:21:44

嗨:我知道你有标签。由于标签无法缩小,因此您需要编写一些代码。

动态地处理报表是一项棘手的任务。当您更改部分的高度或宽度时,所有控件都必须保留在新区域内,否则会出现问题。
当您移动控件时,它必须保持在该部分的区域内,否则您会遇到问题。另外,您应该禁用该部分的自动收缩。

现在,这是一个例子。您应该修改它以满足您的要求。
报告的代码如下:

Option Compare Database
Option Explicit

Private twipsPerLine As Integer     ' The height of a line in your report
Private detailHeight As Integer     ' The height of your detail section
Private vPos As Integer             ' The vertical position of the control
                                'following the one you want to hide

Private Sub Report_Open(Cancel As Integer)
    ' Set the values
    vPos = data_2.Top
    twipsPerLine = data_2.Top - data_1.Top
    detailHeight = Me.Detail.Height
End Sub

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)

    If (IsNull(Me.data_1.Value)) Then
        ' First, you hide the controls
        Me.data_1.Visible = False
        Me.data_1_label.Visible = False
        ' Then, you set the position of the rest of the controls (up)
        data_2_label.Move data_2_label.Left, vPos - twipsPerLine
        data_2.Move data_2.Left, vPos - twipsPerLine
        ' Finally, you shrink the detail section height
        Me.Detail.Height = detailHeight - twipsPerLine
    Else
        ' First, you show the controls
        Me.data_1.Visible = True
        Me.data_1_label.Visible = True
        ' Then, you reset the section height
        Me.Detail.Height = detailHeight
        ' Finally, you reset the position of the rest of the controls
        data_2_label.Move data_2_label.Left, vPos
        data_2.Move data_2.Left, vPos
    End If

End Sub

这种近似方法使您可以完全控制报告,即使报告上有标签、图像或其他内容,它也能正常工作。

在此处输入图像描述

Hi: I understand that you have labels. Since labels cannot shrink, you'll need to write some code.

Dynamically playing with reports is a tricky task. When you change a section's height or width all the controls must keep inside the new area, otherwise you'll have problems.
When you move a control, it must keep inside the section's area, otherwise you'll have problems. Also, you should disable Autoshrink for the section.

Now, this is an example. You should modify it to meet your requirements.
Here goes the code for the report:

Option Compare Database
Option Explicit

Private twipsPerLine As Integer     ' The height of a line in your report
Private detailHeight As Integer     ' The height of your detail section
Private vPos As Integer             ' The vertical position of the control
                                'following the one you want to hide

Private Sub Report_Open(Cancel As Integer)
    ' Set the values
    vPos = data_2.Top
    twipsPerLine = data_2.Top - data_1.Top
    detailHeight = Me.Detail.Height
End Sub

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)

    If (IsNull(Me.data_1.Value)) Then
        ' First, you hide the controls
        Me.data_1.Visible = False
        Me.data_1_label.Visible = False
        ' Then, you set the position of the rest of the controls (up)
        data_2_label.Move data_2_label.Left, vPos - twipsPerLine
        data_2.Move data_2.Left, vPos - twipsPerLine
        ' Finally, you shrink the detail section height
        Me.Detail.Height = detailHeight - twipsPerLine
    Else
        ' First, you show the controls
        Me.data_1.Visible = True
        Me.data_1_label.Visible = True
        ' Then, you reset the section height
        Me.Detail.Height = detailHeight
        ' Finally, you reset the position of the rest of the controls
        data_2_label.Move data_2_label.Left, vPos
        data_2.Move data_2.Left, vPos
    End If

End Sub

This approximation gives you complete control over your report and works even if you have labels, images or whatever on it.

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文