2011-07-29 35 views
3

MS Accessでレポートの詳細領域のサイズを動的に変更できますか?レポートの動的なサイズ変更詳細領域

私はレポートを持っていて、詳細領域には2つの行がありますが、そのうちの1つを「オプション」にしたいと思います。データが表示されず、詳細領域がトップデータの行。

私はこのようなコードを持っている:

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として動作しますが、私は一番下の行が隠されているとき、ディテール領域が縮小することができません。 I は、詳細のCanShrinkプロパティをTrueに設定しましたが、縮小されませんでした。あなたのコントロールのための

答えて

4

設定印刷時縮小あまりにも(たとえばテキストボックス):

enter image description here enter image description here

+0

私はすでにそれをやったと思ったが、私がカップルを逃していたようです。今のように見えます! – FrustratedWithFormsDesigner

+0

これは、ラベルを使用していないか、ラベルとテキストボックスフィールドが混在している場合を除き、機能します。ラベルがある場合、 1)ラベルをテキストボックスに変更し、テキストボックスのプロパティにfalseを表示し、canShrinkプロパティをtrueに設定します。2)Clonの答えを参照してください。 – thecoolmacdude

4

こんにちは:私はあなたがラベルを持っていることを理解しています。ラベルは縮小できないので、コードを書く必要があります。

フォームでダイナミックに遊ぶのは難しい作業です。セクションの高さや幅を変更すると、すべてのコントロールが新しいエリア内に保持されなければなりません。そうしないと、問題が発生します。 コントロールを移動するときは、セクションの領域内に保持する必要があります。そうしないと、問題が発生します。また、セクションの自動縮小を無効にする必要があります。

これは一例です。要件に合わせて変更する必要があります。ここ は、フォームのコードを行く:

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

関連する問題