+ Reply to Thread
Results 1 to 6 of 6

Calling Routine by Variable Name

  1. #1
    Registered User
    Join Date
    05-28-2005
    Location
    WI, USA
    MS-Off Ver
    Office XP/2003
    Posts
    95

    Calling Routine by Variable Name

    Hi,

    I've created a userform that can be the first part of a few different routines. After data is entered on the userform, it will then call a different routine, depending on which routine initially loaded the form. What I'd like to do is store the name of the second routine to call as a string variable and have a simple line of code like "Call tempstring" in the userform, but I'm having trouble doing it. For example, if Routine1 calls the form, the form would then call Routine1Cont. If Routine2 calls it, the form would then call Routine2Cont, etc. If I used
    Please Login or Register  to view this content.
    I get an error. Can anyone think of a way around this?

    Thanks,
    Chris

    P.S. I hope that made sense.

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259
    Hello Caligula,

    The UserForm and most of its controls have a Tag property, which holds a string. This is most commonly used for the purpose you describe. You can set this string to hold information that the next routine or control can use.

    Sincerely,
    Leith Ross

  3. #3
    Registered User
    Join Date
    05-28-2005
    Location
    WI, USA
    MS-Off Ver
    Office XP/2003
    Posts
    95
    Hi Leith,

    Thanks for your response. I'm not sure I understand how to use this though. I tried
    Please Login or Register  to view this content.
    and get an "Invalid Use of Property" error. I know I could use
    Please Login or Register  to view this content.
    and so on and so on. But I'd rather not enumerate every possible string that could be stored there. Can you help me figure out what I'm missing?

    Thanks,
    Chris

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259
    Hello Chris,

    I could answer your questions faster if you can post your workbook. Is that possible?

    Thanks,
    Leith Ross

  5. #5
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591
    Chris

    try using the application.run method.

    In the simple test below, answer the question asked when you run aaa. I know it only gives one default, but this is really just an example.

    So if you have a variable that contains the original calling details, you can append the suffix, and use application.run to call the relevant code.

    hth

    rylo
    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    05-28-2005
    Location
    WI, USA
    MS-Off Ver
    Office XP/2003
    Posts
    95
    That worked like a charm. Thanks rylo!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1