访问:无数据时在子报表中显示文本框控件 [英] Access: Display Textbox Control In Sub-report when it has No Data

查看:93
本文介绍了访问:无数据时在子报表中显示文本框控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在子报表中,我创建了一个有关detail_format事件的子程序,该事件将在没有返回数据时显示文本.

In a subreport I created a sub on detail_format event that will display a text when there is no data returned.

‘Code in sub-report
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)

If Me.Report.HasData Then
    Me.Label43.Visible = True
    Me.txtNotEntered.Visible = False
Else
    Me.Label43.Visible = True
    Me.txtNotEntered.Visible = True
End If

End Sub

单独运行时,在子报表上运行良好.当我运行主报告时,它不会触发.

It works fine on the subreport when run alone. When I run the main report it doesn’t trigger.

我在主报告中添加了相同的代码,以查看它是否有效.它遍历代码行,但仍然看不到txtNotEntered文本框控件.

I added the same code in the main report to see if it would work. It runs through the lines of code but still cannot see the txtNotEntered textbox control.

‘Code in main report
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)

If Me!rptResults_Comments.Report.HasData Then
    Me!rptResults_Comments.Report.Label43.Visible = True
    Me!rptResults_Comments.Report.txtNotEntered.Visible = False
Else
    Me!rptResults_Comments.Visible = True
    Me!rptResults_Comments.Report.Label43.Visible = True
    Me!rptResults_Comments.Report.txtNotEntered.Visible = True
End If

End sub

我正在使用MS Access 2003.

I am using MS Access 2003.

推荐答案

由于子报表已绑定到主报表,因此,如果没有数据将其连接到主报表,则不会显示子报表本身.通过将子报表的详细信息"部分的背景颜色设置为红色或任何其他非白色,您可以更好地看到这一点.

Since the subreport is bound to the main report, the subreport itself will not be shown if there is no data to connect it to the main report. You can see this better by setting the background color of the subreport's detail section to red, or any other non-white color.

一种解决方法是将txtNotEntered控件移至主报表,然后将其置于子报表控件的下方"(使用发送至上一步").然后将子报表控件的Can Shrink属性设置为True.

One workaround is to move your txtNotEntered control to the main report and put it "under" the subreport control (using Send to Back). Then set your subreport control's Can Shrink property to True.

然后,当子报表中有数据时,您将看到该子报表,它将覆盖txtNotEntered控件.没有数据时,子报表将缩小,您将可以看到txtNotEntered控件.

Then, when there is data in the subreport you will see the subreport and it will cover the txtNotEntered control. When there is no data, the subreport will shrink out of the way and you will be able to see the txtNotEntered control.

此方法的一个优点是它不需要任何代码.只需将txtNotEntered Visible属性设置为True.子报表的缩小将在适当的时候进行显示.

One advantage to this approach is that it requires no code. Just leave the txtNotEntered Visible property set to True. The shrinking of the subreport will take care of revealing it when appropriate.

这篇关于访问:无数据时在子报表中显示文本框控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆