Connecting Tech Pros Worldwide Help | Site Map

Run in the same form

Mat N
Guest
 
Posts: n/a
#1: Nov 13 '05
I want to "Run" a procedure in my form by referencing the string that
represents the procedure.

I think Run is the right function to use however it throws me an error
that it can't find the procedure.

Example:

For the button on the form:

Private Sub cmdProcessList_Click()
RunProcedurefromString
End Sub

Public Sub RunProcedurefromString()
Run "TheProcedure" '<--This is where the error occurs
End Sub

Public Sub TheProcedure()
MsgBox "if this shows then Run is doing what I think it should",
vbOKOnly, "It Works!"
End Sub

Can anyone tell me what I'm doing wrong? And/or a better approach.

Thanks

Keith
Guest
 
Posts: n/a
#2: Nov 13 '05

re: Run in the same form


"Mat N" <MatNorth@gmail.com> wrote in message
news:1115893159.992534.19820@g44g2000cwa.googlegro ups.com...
[color=blue]
>
> Public Sub RunProcedurefromString()
> Run "TheProcedure" '<--This is where the error occurs
> End Sub
>[/color]
Try 'Call' or even just the sub's name.

Keith.
www.keithwilby.com


Mat N
Guest
 
Posts: n/a
#3: Nov 13 '05

re: Run in the same form


To use Call and just the sub name however would work but I wouldn't
referring to the procedure using a string.

ie

TheProcedure

or

Call TheProcedure

would work however:

"TheProcedure"

or

Call "TheProcedure"

Would not and all I have is the string that represents the Procedure
name.

Why am I using a string you may ask. Well for the sake of argument you
can assume that I'm pulling names of the procedures from a table.

Lyle Fairfield
Guest
 
Posts: n/a
#4: Nov 13 '05

re: Run in the same form


Mat N wrote:[color=blue]
> To use Call and just the sub name however would work but I wouldn't
> referring to the procedure using a string.[/color]

Application.Run "TheProcedureName", Arg1, Arg2, etc (or no args)

or just

Run "TheProcedureName" Arg1, Arg2, etc (or no args)

Make the procedure a Public Function, not a Public Sub.

BTW, this is required for running code from a macro as well; must be,
TTBOMK, a function, not a sub.

--
--
Lyle

"The aim of those who try to control thought is always the same. They
find one single explanation of the world, one system of thought and
action that will (they believe) cover everything; and then they try to
impose that on all thinking people."
- Gilbert Highet
Gary Floam
Guest
 
Posts: n/a
#5: Nov 13 '05

re: Run in the same form


Hi,

I think you want the Eval method.

Gary

"Mat N" <MatNorth@gmail.com> wrote in message
news:1115893159.992534.19820@g44g2000cwa.googlegro ups.com...[color=blue]
>I want to "Run" a procedure in my form by referencing the string that
> represents the procedure.
>
> I think Run is the right function to use however it throws me an error
> that it can't find the procedure.
>
> Example:
>
> For the button on the form:
>
> Private Sub cmdProcessList_Click()
> RunProcedurefromString
> End Sub
>
> Public Sub RunProcedurefromString()
> Run "TheProcedure" '<--This is where the error occurs
> End Sub
>
> Public Sub TheProcedure()
> MsgBox "if this shows then Run is doing what I think it should",
> vbOKOnly, "It Works!"
> End Sub
>
> Can anyone tell me what I'm doing wrong? And/or a better approach.
>
> Thanks
>[/color]


Mat N
Guest
 
Posts: n/a
#6: Nov 13 '05

re: Run in the same form


I tried the eval method without success.

I've done a less elegant fix to the problem for the time being.

Lyle, when I have a moment I will try out your suggest although I think
I may have already given it a go without success.

Thanks

Closed Thread