你好:我明白你的标签。由于标签无法缩小,因此您需要编写一些代码。
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
这种近似让您完全控制在你的报告,即使你有标签,图像或任何在它的工作原理。
我以为我已经做到了,但似乎我已经错过了一对夫妇。看起来现在起作用了! – FrustratedWithFormsDesigner
除非您使用标签(或混合使用标签和文本框字段),否则此方法可行。如果您有标签,您可以: 1)将标签更改为文本框,在文本框属性中将可见设置为false,并将其canShrink属性设置为true或2)请参阅Clon的答案。 – thecoolmacdude