Executing a procedure when the procedure name is a string

  • Thread starter Thread starter Sam D
  • Start date Start date
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
 
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
 
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
 
Back
Top