将多个变量传递给sub

时间:2016-10-21 12:04:30

标签: access-vba

我想将三个变量传递给子例程。我无法弄清楚语法。我有一个使用一个变量的例子,但是当我将它缩放到两个或更多时我得到一个错误。

这个有效:

Private Sub DateBoxVisible(x As Boolean)
Me.startdate.Visible = x
    Me.lblstartdate.Visible = x
    Me.enddate.Visible = x
    Me.lblenddate.Visible = x
End Sub
Private Sub btnSpecificDate_GotFocus()
     x = True
    DateBoxVisible (x)
End Sub

这一个在最后一行抛出错误(expected =)

Private Sub InitPos(MC As Boolean, AVO As Boolean, UAST As Boolean)
    Me.comboMCName.Visible = MC
    Me.comboAVOName.Visible = AVO
    Me.comboUASTName.Visible = UAST
    Me.optDateRange.Visible = True
End Sub

Private Sub btnAVP_GotFocus()
    MC = False
    AVO = True
    UAST = False
    InitPos (MC,AVO,UAST)
end sub

“initpos(MC,AVO,UAST)中存在语法错误,但我尝试了所有可以想到的组合。

1 个答案:

答案 0 :(得分:0)

尝试更明确:

Option Explicit

Private Sub InitPos(ByVal MC As Boolean, ByVal AVO As Boolean, ByVal UAST As Boolean)

    Me!comboMCName.Visible = MC
    Me!comboAVOName.Visible = AVO
    Me!comboUASTName.Visible = UAST
    Me!optDateRange.Visible = True

End Sub


Private Sub btnAVP_GotFocus()

    Dim MC As Boolean
    Dim AVO As Boolean
    Dim UAST As Boolean

    MC = False
    AVO = True
    UAST = False
    InitPos MC, AVO, UAST

End Sub