Code Assistance

jstevens
GoldLounger
Posts: 2631
Joined: 26 Jan 2010, 16:31
Location: Southern California

Code Assistance

Post by jstevens »

I would like to call a sub-routine based on a series of prompts. One thing to note is that the sub-routine is not envoked immediately after the prompt.

My challenge is that I'm receiving a compile error: Expected Sub, Function or Property

Example:

Code: Select all

oPrompt = InputBox("Your Choices Are: 01, 02 or 03","Entry Required...","Please Enter Your Selection")

If oPrompt = "01" Then
    oSelection = "Run_SubRoutine_01"
ElseIF oPrompt = "02" Then
    oSelection = "Run_SubRoutine_02"
ElseIF oPrompt = "03" Then
    oSelection = "Run_SubRoutine_03"
Else
    'Do Nothing
End IF

'More code here
'More code here
'More code here
'More code here

'*************************************
'Now run the code from the prompt - The compile error happens here.  Each sub-routine ie Run_Subroutine_?? has been coded correctly.
       oSelection
Thank you for taking a look,
John
Regards,
John

User avatar
HansV
Administrator
Posts: 78535
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Code Assistance

Post by HansV »

The line oSelection tries to execute a procedure named oSelection, it doesn't look at the value of the variable oSelection. Try

Application.Run oSelection
Best wishes,
Hans

jstevens
GoldLounger
Posts: 2631
Joined: 26 Jan 2010, 16:31
Location: Southern California

Re: Code Assistance

Post by jstevens »

Hans,

That will do it.

Thank you,
John
Regards,
John