By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,961 Members | 1,320 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,961 IT Pros & Developers. It's quick & easy.

Calling sub and/or function

P: n/a
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
Nov 12 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
On Sat, 17 Jan 2004 21:48:40 +0100, "Jon Ole Hedne"
<jo*****@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 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


Nov 12 '05 #2

P: n/a
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)
The SQL should execute and the form should open.... Exit sub

Jon Ole

"Tom van Stiphout" <to*****@no.spam.cox.net> wrote in message
news:rg********************************@4ax.com... On Sat, 17 Jan 2004 21:48:40 +0100, "Jon Ole Hedne"
<jo*****@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 sub/functionis 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 andexecute the variable, but I can't figure it out...

Thanks :-)

Jon Ole Hedne
Norway

Nov 12 '05 #3

P: n/a
On Sun, 18 Jan 2004 01:14:07 +0100, "Jon Ole Hedne"
<jo*****@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.
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)
The SQL should execute and the form should open....

Exit sub

Jon Ole

"Tom van Stiphout" <to*****@no.spam.cox.net> wrote in message
news:rg********************************@4ax.com.. .
On Sat, 17 Jan 2004 21:48:40 +0100, "Jon Ole Hedne"
<jo*****@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 thesub/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 nameand >execute the variable, but I can't figure it out...
>
>Thanks :-)
>
>Jon Ole Hedne
>Norway
>


Nov 12 '05 #4

P: n/a
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" <to*****@no.spam.cox.net> wrote in message
news:g6********************************@4ax.com...
On Sun, 18 Jan 2004 01:14:07 +0100, "Jon Ole Hedne"
<jo*****@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.
I have now. The Eval-function returns only the value of another function, itdoesn't actually run the function (or sub). One procedure could be somethinglike 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)
The SQL should execute and the form should open....

Exit sub

Jon Ole

"Tom van Stiphout" <to*****@no.spam.cox.net> wrote in message
news:rg********************************@4ax.com.. .
On Sat, 17 Jan 2004 21:48:40 +0100, "Jon Ole Hedne"
<jo*****@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

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
nameand
>execute the variable, but I can't figure it out...
>
>Thanks :-)
>
>Jon Ole Hedne
>Norway
>

Nov 12 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.