OnAction function with arguments

  • Thread starter Thread starter JonWayne
  • Start date Start date
J

JonWayne

Can the OnAction property of a commandbarbutton be set to call a function
with arguments? If so, how is it formatted?
 
Can the OnAction property of a commandbarbutton be set to call a function
with arguments? If so, how is it formatted?

Write a Sub procedure that obtains the arguments and calls the Function,
then call the sub from the commandbarbutton.
 
I was hoping for an example. I have the function written, which accepts 2
String arguments. Its the OnAction setting is what I am unsure about, which
is a string - and in this case, passing 2 strings to a calling function. How
do I write it? OnAction = "SomeFunc(""StrArg1"",""StrArg2"")". Would that be
an example of how its is quoted?

Thanks
 
JonWayne said:
I was hoping for an example. I have the function written, which accepts 2
String arguments. Its the OnAction setting is what I am unsure about, which
is a string - and in this case, passing 2 strings to a calling function. How
do I write it? OnAction = "SomeFunc(""StrArg1"",""StrArg2"")". Would that be
an example of how its is quoted?

If you are using literals...

=SomeFunc("String1", "String2")

If you are using variables...

=SomeFunc(Var1, Var2)
 
I haven't tried your solution, but , are you sure that will work? The reason
I am asking is that I have done this several times and have had it work,
except without arguments, and as for as I remember, even the FunctionName
itself is enclosed in quotes - example: if the function I am calling is
named FuncSum , the OnAction property setting would look like -: OnAction =
"FuncSum()" or probably OnAction = "=FuncSum()". I will check it when I
get a chance tonight, but if you have more to add please do - thanks.
 
Public Sub CallMyFunction()
Dim RetVal As Variant

RetVal = MyFunction(Argument1, Argument2)

End Sub



I was hoping for an example. I have the function written, which accepts 2
String arguments. Its the OnAction setting is what I am unsure about, which
is a string - and in this case, passing 2 strings to a calling function. How
do I write it? OnAction = "SomeFunc(""StrArg1"",""StrArg2"")". Would that be
an example of how its is quoted?

Thanks
 
Somehow, I must not be explaining myself properly here. If you had to set
the OnAction property to call a function which takes 2 string args, how
would you enter that setting? Note, the function is already written, I
dont need to know how to write a function. What I need to know is how to set
the OnAction property to call the function, passing the 2 arguments.



John Nurick said:
Public Sub CallMyFunction()
Dim RetVal As Variant

RetVal = MyFunction(Argument1, Argument2)

End Sub
 
JonWayne said:
Somehow, I must not be explaining myself properly here. If you had to set
the OnAction property to call a function which takes 2 string args, how
would you enter that setting? Note, the function is already written, I
dont need to know how to write a function. What I need to know is how to set
the OnAction property to call the function, passing the 2 arguments.

Are you asking how to do this *in code* or how to do this yourself using the
GUI?

If I am customizing a toolbar I would right-click the desired button and in the
OnAction property I would type...

=FunctionName(Variable1, Variable2)

This assumes that those are public variables, but if they are that is exactly
how the On Action would be entered. There would be no Quotes around the entry
and there would be no quotes around the arguments unless I was using a string
literal rather than a variable.

If you are trying to assign the On Action event to a button *in code* then yes,
you would likely need to wrap the entire On Action entry in quotes, but you have
never indicated that this is what you are trying to do.
 
Sorry if my tone in the last post sounded harsh - that was not my intention.
However, thats right, I am asking about doing it *in codes*. I probably did
not make that real clear either, but that is what I am looking for. Thanks
 
Back
Top