Connecting Tech Pros Worldwide Help | Site Map

Calling sub and/or function

Jon Ole Hedne
Guest
 
Posts: n/a
#1: Nov 12 '05
I have a possibly stupid question - thought it was simple to do....

From vba code I want to call a sub or function. The name of the sub/function
is stored in a table. I want to achieve something like this:

.....
rs.open, mytable, conn
'Here is the problem-line:
call rs!function_name
'And here should the sub/function run...

Probably I have to declare a variable, set its name to the function name and
execute the variable, but I can't figure it out...

Thanks :-)

Jon Ole Hedne
Norway


Tom van Stiphout
Guest
 
Posts: n/a
#2: Nov 12 '05

re: Calling sub and/or function


On Sat, 17 Jan 2004 21:48:40 +0100, "Jon Ole Hedne"
<johedne@online.no> wrote:

Check out the Eval function in the Help file.
-Tom.

[color=blue]
>I have a possibly stupid question - thought it was simple to do....
>
>From vba code I want to call a sub or function. The name of the sub/function
>is stored in a table. I want to achieve something like this:
>
>....
>rs.open, mytable, conn
>'Here is the problem-line:
>call rs!function_name
>'And here should the sub/function run...
>
>Probably I have to declare a variable, set its name to the function name and
>execute the variable, but I can't figure it out...
>
>Thanks :-)
>
>Jon Ole Hedne
>Norway
>[/color]

Jon Ole Hedne
Guest
 
Posts: n/a
#3: Nov 12 '05

re: Calling sub and/or function


I have now. The Eval-function returns only the value of another function, it
doesn't actually run the function (or sub). One procedure could be something
like this:
Public Sub Etiketter()
Docmd.runSql "Select something..."
DoCmd.OpenForm "TheForm", acNormal
End Sub

Public Sub RunOnClick()
rs.open, mytable, conn
call rs!function_name (Which contains "Etiketter" Or "Etiketter()" Or
Etiketter)[color=blue]
> The SQL should execute and the form should open....[/color]
Exit sub

Jon Ole

"Tom van Stiphout" <tom7744@no.spam.cox.net> wrote in message
news:rg9j00dt4urk4lp13a2cp6dqnlh5s1rai3@4ax.com...[color=blue]
> On Sat, 17 Jan 2004 21:48:40 +0100, "Jon Ole Hedne"
> <johedne@online.no> wrote:
>
> Check out the Eval function in the Help file.
> -Tom.
>
>[color=green]
> >I have a possibly stupid question - thought it was simple to do....
> >
> >From vba code I want to call a sub or function. The name of the[/color][/color]
sub/function[color=blue][color=green]
> >is stored in a table. I want to achieve something like this:
> >
> >....
> >rs.open, mytable, conn
> >'Here is the problem-line:
> >call rs!function_name
> >'And here should the sub/function run...
> >
> >Probably I have to declare a variable, set its name to the function name[/color][/color]
and[color=blue][color=green]
> >execute the variable, but I can't figure it out...
> >
> >Thanks :-)
> >
> >Jon Ole Hedne
> >Norway
> >[/color]
>[/color]


Tom van Stiphout
Guest
 
Posts: n/a
#4: Nov 12 '05

re: Calling sub and/or function


On Sun, 18 Jan 2004 01:14:07 +0100, "Jon Ole Hedne"
<johedne@online.no> wrote:

Oh, yes it does.
Think about it. You're saying that the Eval function "only" returns
the value of another function. How do you think it computes the return
value? Of course by running that function!

Eval works only with functions, not with subs. Rewrite your subs as
functions.

Debug.Print Eval("MyFunction()")

-Tom.


[color=blue]
>I have now. The Eval-function returns only the value of another function, it
>doesn't actually run the function (or sub). One procedure could be something
>like this:
>Public Sub Etiketter()
> Docmd.runSql "Select something..."
> DoCmd.OpenForm "TheForm", acNormal
>End Sub
>
>Public Sub RunOnClick()
>rs.open, mytable, conn
>call rs!function_name (Which contains "Etiketter" Or "Etiketter()" Or
>Etiketter)[color=green]
>> The SQL should execute and the form should open....[/color]
>Exit sub
>
>Jon Ole
>
>"Tom van Stiphout" <tom7744@no.spam.cox.net> wrote in message
>news:rg9j00dt4urk4lp13a2cp6dqnlh5s1rai3@4ax.com.. .[color=green]
>> On Sat, 17 Jan 2004 21:48:40 +0100, "Jon Ole Hedne"
>> <johedne@online.no> wrote:
>>
>> Check out the Eval function in the Help file.
>> -Tom.
>>
>>[color=darkred]
>> >I have a possibly stupid question - thought it was simple to do....
>> >
>> >From vba code I want to call a sub or function. The name of the[/color][/color]
>sub/function[color=green][color=darkred]
>> >is stored in a table. I want to achieve something like this:
>> >
>> >....
>> >rs.open, mytable, conn
>> >'Here is the problem-line:
>> >call rs!function_name
>> >'And here should the sub/function run...
>> >
>> >Probably I have to declare a variable, set its name to the function name[/color][/color]
>and[color=green][color=darkred]
>> >execute the variable, but I can't figure it out...
>> >
>> >Thanks :-)
>> >
>> >Jon Ole Hedne
>> >Norway
>> >[/color]
>>[/color]
>[/color]

Jon Ole Hedne
Guest
 
Posts: n/a
#5: Nov 12 '05

re: Calling sub and/or function


Of course ...:-) It works now - I had used wrong string-formatting in my
table ("MyProc()" instead of MyProc())... Thanks a lot for your help!

Jon Ole

"Tom van Stiphout" <tom7744@no.spam.cox.net> wrote in message
news:g6vj00hq8t8goabl75ab7ft9qjm43v3ve8@4ax.com...[color=blue]
> On Sun, 18 Jan 2004 01:14:07 +0100, "Jon Ole Hedne"
> <johedne@online.no> wrote:
>
> Oh, yes it does.
> Think about it. You're saying that the Eval function "only" returns
> the value of another function. How do you think it computes the return
> value? Of course by running that function!
>
> Eval works only with functions, not with subs. Rewrite your subs as
> functions.
>
> Debug.Print Eval("MyFunction()")
>
> -Tom.
>
>
>[color=green]
> >I have now. The Eval-function returns only the value of another function,[/color][/color]
it[color=blue][color=green]
> >doesn't actually run the function (or sub). One procedure could be[/color][/color]
something[color=blue][color=green]
> >like this:
> >Public Sub Etiketter()
> > Docmd.runSql "Select something..."
> > DoCmd.OpenForm "TheForm", acNormal
> >End Sub
> >
> >Public Sub RunOnClick()
> >rs.open, mytable, conn
> >call rs!function_name (Which contains "Etiketter" Or "Etiketter()" Or
> >Etiketter)[color=darkred]
> >> The SQL should execute and the form should open....[/color]
> >Exit sub
> >
> >Jon Ole
> >
> >"Tom van Stiphout" <tom7744@no.spam.cox.net> wrote in message
> >news:rg9j00dt4urk4lp13a2cp6dqnlh5s1rai3@4ax.com.. .[color=darkred]
> >> On Sat, 17 Jan 2004 21:48:40 +0100, "Jon Ole Hedne"
> >> <johedne@online.no> wrote:
> >>
> >> Check out the Eval function in the Help file.
> >> -Tom.
> >>
> >>
> >> >I have a possibly stupid question - thought it was simple to do....
> >> >
> >> >From vba code I want to call a sub or function. The name of the[/color]
> >sub/function[color=darkred]
> >> >is stored in a table. I want to achieve something like this:
> >> >
> >> >....
> >> >rs.open, mytable, conn
> >> >'Here is the problem-line:
> >> >call rs!function_name
> >> >'And here should the sub/function run...
> >> >
> >> >Probably I have to declare a variable, set its name to the function[/color][/color][/color]
name[color=blue][color=green]
> >and[color=darkred]
> >> >execute the variable, but I can't figure it out...
> >> >
> >> >Thanks :-)
> >> >
> >> >Jon Ole Hedne
> >> >Norway
> >> >
> >>[/color]
> >[/color]
>[/color]


Closed Thread