multiple argument subs vba

78,070

Solution 1

When using multiple arguments, you can either write:

 setInterest "myAccount", 3

Or

 Call setInterest("myAccount", 3)

In both examples you can name the arguments:

setInterest account:="myAccount", dmonth:= 3

Solution 2

I add this answer, for Why your syntax works with one argument ?

Public Sub setInterest(account As String)
    '...somecode...
End Sub

setInterest ("myAccount")

Note :
When there is not any , between ( and ), VBA thinks it's a formula and exactly one argument.

When formula calculate the result will be like this:

Dim str As String
str = ("TEST")
Debug.Print str

[Output:]
TEST
Share:
78,070

Related videos on Youtube

user1302398
Author by

user1302398

Updated on April 14, 2020

Comments

  • user1302398
    user1302398 about 4 years

    Using VBA with Access 2010, I have a sub:

    Public Sub setInterest(account As String, dmonth As Integer)
        ...somecode...
    End Sub
    

    And I am calling it with

    setInterest("myAccount",3)
    

    And I get syntax errors.
    Modifying the sub to only take one argument and leaving out the 3 gives no errors, the problem is only when I have 2 arguments.

    • Jean-François Corbett
      Jean-François Corbett about 12 years
      duplicate of Calling a Sub in VBA... and many others. This issue has been answered multiple times already.