can I call a procedure using a variable

S

Santiago Gomez

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
 
R

Rob van Gelder

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
 
S

Santiago Gomez

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?
 
T

Tim Zych

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..
 
S

Santiago Gomez

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.
 
T

Tim Zych

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.
 
S

Santiago Gomez

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
 
Top