I have the following Sub:
Public Function Log(sdsMessage As CStandardPropertySet2)
' Only print the fields contained int he sdsMessage
End Function
and I use it like this:
Log(anSdsMessage)
However this results in the Argument not optional error.
But if I have the sub like this:
Public Function Log(sdsMessage As CStandardPropertySet2) As CStandardPropertySet2
' Only print the fields contained int he sdsMessage
Set Log = sdsMessage
End Function
Set anSdsMessage = Log(anSdsMessage)
Then the error disappears. This looks very awkward to me as I do not need to modify the message at all and only want to print the fields in it.
Could someone please tell me what I am doing wrong?
This is silly confusing VBA syntax. when you are jsut calling
Logas a method and have no return type you omit the parentheses.so
Log anSdsMessagewhen no return value is setand (correctly as you have it already)
Set anSdsMessage = Log(anSdsMessage)when a return value is set.To address Daniel’s comment
I can write this code
And try to run the
testersub and I get the error message “Compile error: Argument not optional”Removing the parentheses and running
Log odoes in fact allow compilation and removes the error.