2011-07-29 34 views
3

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

我有一个报告,Detail区域有2行,我希望其中的一个是“可选的” - 当没有数据时它不应该显示,Detail区域应该只与顶部一样高数据行。

我有这样的代码:

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 

它尽可能makign标签和文本框有条件可见的作品,但我不能让细节区收缩时的底线是隐藏的。我确实设置CanShrink属性的细节为True,但它不收缩。

回答

4

套装可以缩小您控制太(例如文本框):

enter image description here enter image description here

+0

我以为我已经做到了,但似乎我已经错过了一对夫妇。看起来现在起作用了! – FrustratedWithFormsDesigner

+0

除非您使用标签(或混合使用标签和文本框字段),否则此方法可行。如果您有标签,您可以: 1)将标签更改为文本框,在文本框属性中将可见设置为false,并将其canShrink属性设置为true或2)请参阅Clon的答案。 – thecoolmacdude

4

你好:我明白你的标签。由于标签无法缩小,因此您需要编写一些代码。

Dinamically玩形式是一项棘手的任务。当您更改某个区域的高度或宽度时,所有控件都必须保留在新区域内,否则您将遇到问题。 当您移动控件时,它必须保持在该区域的区域内,否则您将遇到问题。另外,您应该为该部分禁用Autoshrink。

现在,这是一个例子。您应该修改它以符合您的要求。 这里去的代码形式:

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 

这种近似让您完全控制在你的报告,即使你有标签,图像或任何在它的工作原理。

enter image description here

+0

另一种方法是将标签更改为文本框,在文本框属性中将可见设置为false,并将其canShrink属性设置为true。 – thecoolmacdude