472,119 Members | 1,552 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,119 software developers and data experts.

Calling sub and/or function

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
4 15997
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
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
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
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.

Similar topics

8 posts views Thread by Muthu | last post: by
6 posts views Thread by jchao123 | last post: by
1 post views Thread by Jesse McGrew | last post: by
5 posts views Thread by Nick Flandry | last post: by
2 posts views Thread by Geler | last post: by
15 posts views Thread by dspfun | last post: by
11 posts views Thread by briankirkpatrick | last post: by
16 posts views Thread by teju | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.