+ Reply to Thread
Results 1 to 11 of 11

Help converting String to Form Object Name

  1. #1
    Registered User
    Join Date
    10-26-2012
    Location
    Seattle, WA
    MS-Off Ver
    Excel 2010
    Posts
    6

    Help converting String to Form Object Name

    I want to know if it is possible to use a string variable to reference a form object name.

    Capture.PNG

    I have 9 check boxes and 9 text boxes, and I only want each text box to be enabled if the subsequent check box is checked.
    The check boxes are named Dur1, Dur2, ... , Dur9. The text boxes are named Setup1, Setup2, ... , Setup9.

    I want to do something like this, but can't figure out how:

    Please Login or Register  to view this content.
    This code obviously doesn't work.. Is there a way that I can do this?

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Help converting String to Form Object Name

    If this is on a userform you can use the form's Controls collection.
    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    10-26-2012
    Location
    Seattle, WA
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Help converting String to Form Object Name

    Thanks! I will give this a try

  4. #4
    Registered User
    Join Date
    10-26-2012
    Location
    Seattle, WA
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Help converting String to Form Object Name

    I tried this and I am getting a "Could not find object" error for Me.Controls(SetupStr)

  5. #5
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Help converting String to Form Object Name

    That could be because you used Str.

    You don't need to convert the number to a string and when you do using Str a space is added at the front.

    So in the code you are generating names like 'Dur 1' instead of 'Dur1'.

  6. #6
    Registered User
    Join Date
    10-26-2012
    Location
    Seattle, WA
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Help converting String to Form Object Name

    Finally working! Just had to use CStr. Thanks!

  7. #7
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Help converting String to Form Object Name

    You shouldn't need to use anything.

    This will work just fine.
    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    10-26-2012
    Location
    Seattle, WA
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Help converting String to Form Object Name

    For some reason that was giving me a type mismatch..

    Do I have to declare DurStr as something other than a String?

  9. #9
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Help converting String to Form Object Name

    It would be giving that error because you used + instead of &.

  10. #10
    Registered User
    Join Date
    10-26-2012
    Location
    Seattle, WA
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Help converting String to Form Object Name

    That was indeed the problem. Thanks again!

  11. #11
    Forum Expert Cutter's Avatar
    Join Date
    05-24-2004
    Location
    Ontario,Canada
    MS-Off Ver
    Excel 2010
    Posts
    6,451

    Re: Help converting String to Form Object Name

    @ buley004

    Welcome to the forum.

    Based on your last post it seems that you are satisfied with the solution(s) you've received but you haven't marked your thread as SOLVED. I'll do that for you now but please keep in mind for your future threads that Rule #9 requires you to do that yourself. If your problem has not been solved you can use Thread Tools (located above your first post) and choose "Mark this thread as unsolved".
    Thanks.

    Also, as a new member of the forum, you may not be aware that you can thank those who have helped you by clicking the small star icon located in the lower left corner of the post in which the help was given. By doing so you can add to the reputation(s) of those who helped.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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