VBA - 如果ElseIf与.Visible = True / False

时间:2015-03-19 19:16:36

标签: vba ms-access

我希望我可以在遇到的VBA问题上得到一些帮助,但首先我想说的是,我绝不是VBA的专家,或者任何接近这个的人......但是,我很渴望学习!

我正在使用MS Access 2010中的报告并使用VBA,我隐藏了1页页脚并根据页码显示另一页脚。我遇到的问题是,我需要在报告中将页脚隐藏起来并且不可思议。我试图使用IF ELSEIF,但似乎没有用。这段代码看起来是否正确?或者我做错了什么?

If Me.Page <= 2 Then
    Me.PageFooter1.Visible = True
    Me.PageFooter2.Visible = False
ElseIf Me.Page >= 9 Then
    Me.PageFooter1.Visible = True
    Me.PageFooter2.Visible = False
Else
    Me.PageFooter1.Visible = False
    Me.PageFooter2.Visible = True
End If

提前感谢您的帮助!

1 个答案:

答案 0 :(得分:2)

嗯,前两个条件是做同样的事情:

If Me.Page <= 2 Then
    Me.PageFooter1.Visible = True
    Me.PageFooter2.Visible = False
ElseIf Me.Page >= 9 Then
    Me.PageFooter1.Visible = True
    Me.PageFooter2.Visible = False

页面是否小于或等于2,或页面是否大于或等于9,则:

Me.PageFooter1.Visible = True
Me.PageFooter2.Visible = False

否则(因此,如果页面大于2但小于9):

Me.PageFooter1.Visible = False
Me.PageFooter2.Visible = True

这将改写为:

 If Me.Page <= 2 Or Me.Page >= 9 Then
     Me.PageFooter1.Visible = True
     Me.PageFooter2.Visible = False
 Else
     Me.PageFooter1.Visible = False
     Me.PageFooter2.Visible = True
 End If

但那仍然看起来很奇怪。看起来你有2个“页脚样式”在这里。如何引入这个概念?

 Dim showFooterStyle1 As Boolean
 showFooterStyle1 = (Me.Page <= 2 Or Me.Page >= 9)

 Me.PageFooter1.Visible = showFooterStyle1
 Me.PageFooter2.Visible = Not showFooterStyle1

现在,从你提出的问题来看,这是否是你想要完成的事情还不清楚。但至少应该更容易看出问题所在。