multiple argument subs vba

痞子三分冷 提交于 2019-12-03 14:53:27

问题


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.


回答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



回答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


来源:https://stackoverflow.com/questions/10152306/multiple-argument-subs-vba

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!