0

I want to pass three variables to a sub routine. I cannot figure out the syntax. I have an example which works with one variable, but I get an error when I scale it to two or more.

This one works:

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

This one throws an error (expected =) on the last line

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

There is a syntax error in " initpos(MC,AVO,UAST) but I have tried every combination I can think of.

Erik A
  • 31,639
  • 12
  • 42
  • 67
Robert Kendall
  • 368
  • 2
  • 9
  • 24
  • Possible duplicate of [Calling a Sub in VBA](http://stackoverflow.com/questions/7715044/calling-a-sub-in-vba) – Andre Oct 21 '16 at 12:06
  • also http://stackoverflow.com/questions/23796803/vba-whats-the-underlying-difference-between-call-sub-or-function-with-or-withou – Andre Oct 21 '16 at 12:11

1 Answers1

0

Try to be more explicit:

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
Gustav
  • 53,498
  • 7
  • 29
  • 55