Executing a procedure when the procedure name is a string

S

Sam D

Hi and thanks for you help,

(Also posted to .modulescoding but has not yet appeared in my news reader)

I need to execute a procedure within another form from a procedure in a
module when the name of the procedure is generated using a string. I thought
Application.Run would do the job, however it generates runtime error 2517
(meaning it cannot find the procedure). The procedures can be run directly,
but not using Application.Run.

Is there another command that will solve my problem?

Code fragment follows...

'does this control require its AfterUpdate event to be executed
If .Controls(rs("ControlName")).Tag = "SU" Then
'run the controls AfterUpdate event procedure
'SAM these procedures must be public (not great but does the
job).

'Forms![Print Reports].cbo1_AfterUpdate <= THIS WORKS FINE

Application.Run "Forms![Print Reports]." & rs("ControlName") &
"_AfterUpdate" <= GENERATES ERROR 2517

End If

Regards,

Sam
 
J

John Nurick

Hi Sam,

Check out CallByName() and Eval(). One lets you call a method or access
a property of an object, and the other evaluates an expression (so you
can use it to execute a Function but not a Sub).

Hi and thanks for you help,

(Also posted to .modulescoding but has not yet appeared in my news reader)

I need to execute a procedure within another form from a procedure in a
module when the name of the procedure is generated using a string. I thought
Application.Run would do the job, however it generates runtime error 2517
(meaning it cannot find the procedure). The procedures can be run directly,
but not using Application.Run.

Is there another command that will solve my problem?

Code fragment follows...

'does this control require its AfterUpdate event to be executed
If .Controls(rs("ControlName")).Tag = "SU" Then
'run the controls AfterUpdate event procedure
'SAM these procedures must be public (not great but does the
job).

'Forms![Print Reports].cbo1_AfterUpdate <= THIS WORKS FINE

Application.Run "Forms![Print Reports]." & rs("ControlName") &
"_AfterUpdate" <= GENERATES ERROR 2517

End If

Regards,

Sam
 
S

Sam D

Thanks John, CallByName works great!

John Nurick said:
Hi Sam,

Check out CallByName() and Eval(). One lets you call a method or access
a property of an object, and the other evaluates an expression (so you
can use it to execute a Function but not a Sub).

Hi and thanks for you help,

(Also posted to .modulescoding but has not yet appeared in my news reader)

I need to execute a procedure within another form from a procedure in a
module when the name of the procedure is generated using a string. I
thought
Application.Run would do the job, however it generates runtime error 2517
(meaning it cannot find the procedure). The procedures can be run
directly,
but not using Application.Run.

Is there another command that will solve my problem?

Code fragment follows...

'does this control require its AfterUpdate event to be executed
If .Controls(rs("ControlName")).Tag = "SU" Then
'run the controls AfterUpdate event procedure
'SAM these procedures must be public (not great but does the
job).

'Forms![Print Reports].cbo1_AfterUpdate <= THIS WORKS FINE

Application.Run "Forms![Print Reports]." & rs("ControlName") &
"_AfterUpdate" <= GENERATES ERROR 2517

End If

Regards,

Sam
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top