Results 1 to 4 of 4

Thread: Using string value a command button name

  1. #1
    Neophyte Errdickasin's Avatar
    Join Date
    Oct 2019
    Posts
    3
    Articles
    0
    Excel Version
    latest

    Using string value a command button name



    Register for a FREE account, and/
    or Log in to avoid these ads!

    I pass the name of a command button to a string variable, then do several subroutines. After finishing the subroutines I want to put a value back to that particular command button. What is the command so that it will recognize the string as a command button? Use of Function will not work here.

  2. #2
    Conjurer Kenneth Hobson's Avatar
    Join Date
    Mar 2014
    Location
    Tecumseh, OK
    Posts
    136
    Articles
    0
    Excel Version
    365
    Welcome to the forum!

    What is your code? Is the command button a form control or activex control?

    Strings are not command buttons so I don't know what you mean by:
    What is the command so that it will recognize the string as a command button?

  3. #3
    Neophyte Errdickasin's Avatar
    Join Date
    Oct 2019
    Posts
    3
    Articles
    0
    Excel Version
    latest
    Quote Originally Posted by Errdickasin View Post
    I pass the name of a command button to a string variable, then do several subroutines. After finishing the subroutines I want to put a value back to that particular command button. What is the command so that it will recognize the string as a command button? Use of Function will not work here.
    I found what I was looking for by going to a program I had written several years ago. Thanks for the reply, I was starting to lose hope.
    Using VBA, here was my situation:
    I have several command buttons on a form. I use them so the end user is limited to the amount of wrong answers they can enter.
    For clarity, let's say I have named that button "Peaches"
    When the end user presses that button, the string "Peaches" gets passed to the tag value of a label (let's call it "Bushels").
    Lots of other actions, subroutines, and the like now happen, but eventually, a value (let's say 42) is to be put back to the Peaches command button tag value. The only way I know that it is supposed to go to the Peaches command button as opposed to some other button, is that it is noted in Bushels.Tag
    Bushels.Tag = 42 'this code will only change the value of Bushels.Tag.
    Controls(Bushels.Tag).Tag = 42 'The word "Controls" was what I was looking for. This will now take the string that is in Bushels.Tag and use it as if it is the command button Peaches, resulting in 42 being placed in Peaches.Tag.

  4. #4
    Neophyte Errdickasin's Avatar
    Join Date
    Oct 2019
    Posts
    3
    Articles
    0
    Excel Version
    latest
    Thanks for responding, I was starting to lose hope.
    I found what I was looking for; it is the word "Controls"
    Here was the situation:
    I have several command buttons on a form (a way for end users to use the form without screwing up)
    Pressing a button (let's call it "Peaches") starts other actions and allows for other interactions with the end user, but also passes its name to the tag value of a label (let's call it Bushels).
    After a while, a value (e.g. 42) is derived and needs to go back to the Command Button, known only because its name is at Bushels.Tag
    Bushels.Tag = 42 only puts the string 42 into the Bushels.Tag
    Controls(Bushels.Tag).Tag gets the string 42 into the Peaches.Tag.

Posting Permissions

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