ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   can I call a procedure using a variable (https://www.excelbanter.com/excel-programming/286169-can-i-call-procedure-using-variable.html)

Santiago Gomez

can I call a procedure using a variable
 
can I call a procedure with a variable as part of the procedure's name?

I have a whole bunch of procedures named something_somethingelse_click()

can I concatenate 2 variables and make them part of the call?

thanks



Rob van Gelder[_4_]

can I call a procedure using a variable
 
Your request confuses me.

I don't know of a way to discover the procedure name that is running.
for example - this doesn't exist:
sub mytestproc()
msgbox application.current_procedure_running()
end sub

If you're asking if one procedure could handle lots of different events -I
think VB.NET handles this well. I don't know when Excel will start using
this (or if it has already in XL2003)

If none of the above fits, you could do similar to the following:

sub something_somethingelse_click()
something "somethingelse"
end sub

sub something_somethingdifferent_click()
something "somethingdifferent"
end sub

sub something(strvariable as string)
if strvariable = "somethingelse" then
msgbox "wow!"
elseif strvariable = "somethingdifferent" then
msgbox "that's a relief"
else
msgbox "no idea!"
end if
end sub



"Santiago Gomez" wrote in message
...
can I call a procedure with a variable as part of the procedure's name?

I have a whole bunch of procedures named something_somethingelse_click()

can I concatenate 2 variables and make them part of the call?

thanks





Tim Zych[_4_]

can I call a procedure using a variable
 
Application.Run StringVar


"Santiago Gomez" wrote in message
...
can I call a procedure with a variable as part of the procedure's name?

I have a whole bunch of procedures named something_somethingelse_click()

can I concatenate 2 variables and make them part of the call?

thanks





Santiago Gomez

can I call a procedure using a variable
 
Thanks, I think this is what I need, however, I get errors when I try
running a procedure this way.
This is what I have...a simple example:

Sub ProcedureOne()
Application.Run "mysub1", "test"
End Sub

Sub mysub1(sTemp As String)
Debug.Print sTemp
End Sub

When I run this I get Error 2517, "Can't find the procedure 'mysub1.'.

I've tried, no quotes, single quotes, etc.

any ideas?


"Tim Zych" wrote in message
...
Application.Run StringVar


"Santiago Gomez" wrote in message
...
can I call a procedure with a variable as part of the procedure's name?

I have a whole bunch of procedures named

something_somethingelse_click()

can I concatenate 2 variables and make them part of the call?

thanks







Tim Zych[_4_]

can I call a procedure using a variable
 
It works for me. Do you have any syntax errors anywhere else in your
project? Add Option Explicit to every module and sheet then Debug -
Compile..


"Santiago Gomez" wrote in message
...
Thanks, I think this is what I need, however, I get errors when I try
running a procedure this way.
This is what I have...a simple example:

Sub ProcedureOne()
Application.Run "mysub1", "test"
End Sub

Sub mysub1(sTemp As String)
Debug.Print sTemp
End Sub

When I run this I get Error 2517, "Can't find the procedure 'mysub1.'.

I've tried, no quotes, single quotes, etc.

any ideas?


"Tim Zych" wrote in message
...
Application.Run StringVar


"Santiago Gomez" wrote in message
...
can I call a procedure with a variable as part of the procedure's

name?

I have a whole bunch of procedures named

something_somethingelse_click()

can I concatenate 2 variables and make them part of the call?

thanks









Santiago Gomez

can I call a procedure using a variable
 
doh!, I just realized I am in the wrong application. I am using Access, not
excel.
sorry guys,
i added th option explicit but it still doesnt work.

I do get the intelli popup thingie when I type Application.Run, is this a
difference between access and excel?

thanks anyway for your help.


"Tim Zych" wrote in message
...
It works for me. Do you have any syntax errors anywhere else in your
project? Add Option Explicit to every module and sheet then Debug -
Compile..


"Santiago Gomez" wrote in message
...
Thanks, I think this is what I need, however, I get errors when I try
running a procedure this way.
This is what I have...a simple example:

Sub ProcedureOne()
Application.Run "mysub1", "test"
End Sub

Sub mysub1(sTemp As String)
Debug.Print sTemp
End Sub

When I run this I get Error 2517, "Can't find the procedure 'mysub1.'.

I've tried, no quotes, single quotes, etc.

any ideas?


"Tim Zych" wrote in message
...
Application.Run StringVar


"Santiago Gomez" wrote in message
...
can I call a procedure with a variable as part of the procedure's

name?

I have a whole bunch of procedures named

something_somethingelse_click()

can I concatenate 2 variables and make them part of the call?

thanks











Tim Zych[_4_]

can I call a procedure using a variable
 
Don't know why it's not working for you. I tried it in Access 2000 and it
worked. Does it help if you try it out in a new database? Also make sure
that mysub1 procedure is Public and not Private.


"Santiago Gomez" wrote in message
...
doh!, I just realized I am in the wrong application. I am using Access,

not
excel.
sorry guys,
i added th option explicit but it still doesnt work.

I do get the intelli popup thingie when I type Application.Run, is this a
difference between access and excel?

thanks anyway for your help.


"Tim Zych" wrote in message
...
It works for me. Do you have any syntax errors anywhere else in your
project? Add Option Explicit to every module and sheet then Debug -
Compile..


"Santiago Gomez" wrote in message
...
Thanks, I think this is what I need, however, I get errors when I try
running a procedure this way.
This is what I have...a simple example:

Sub ProcedureOne()
Application.Run "mysub1", "test"
End Sub

Sub mysub1(sTemp As String)
Debug.Print sTemp
End Sub

When I run this I get Error 2517, "Can't find the procedure

'mysub1.'.

I've tried, no quotes, single quotes, etc.

any ideas?


"Tim Zych" wrote in message
...
Application.Run StringVar


"Santiago Gomez" wrote in message
...
can I call a procedure with a variable as part of the procedure's

name?

I have a whole bunch of procedures named
something_somethingelse_click()

can I concatenate 2 variables and make them part of the call?

thanks













Santiago Gomez

can I call a procedure using a variable
 
this is strange. I tried a new database and still get an error that it
can't find the procedure.
I am running this from a form's code. Should that matter? It is not a
module.

do I need any special References?

Option Compare Database
Option Explicit

Private Sub cmdCall_Click()
Application.Run "MySub1", "temp"
End Sub

Sub MySub1(sTemp As String)
Me.txtBox1.Value = sTemp
End Sub



Tim Zych[_4_]

can I call a procedure using a variable
 
I am running this from a form's code. Should that matter? It is not a
module.


Apparently that makes a big difference.

http://groups.google.com/groups?q=ap...+form+micro s
oft.public.access&start=10&hl=en&lr=&ie=UTF-8&oe=UTF-8&selm=emDlXTCVDHA.964%
40TK2MSFTNGP09.phx.gbl&rnum=12


"Santiago Gomez" wrote in message
...
this is strange. I tried a new database and still get an error that it
can't find the procedure.
I am running this from a form's code. Should that matter? It is not a
module.

do I need any special References?

Option Compare Database
Option Explicit

Private Sub cmdCall_Click()
Application.Run "MySub1", "temp"
End Sub

Sub MySub1(sTemp As String)
Me.txtBox1.Value = sTemp
End Sub






All times are GMT +1. The time now is 08:14 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com