+ Reply to Thread
Results 1 to 16 of 16

Declaring specific userform variables/checkbox

  1. #1
    Registered User
    Join Date
    01-07-2010
    Location
    Dorothy and Todo Land, KS
    MS-Off Ver
    Office 2003 & 2007
    Posts
    34

    Declaring specific userform variables/checkbox

    Hello -

    I'm fairly new to Excel so forgive me if these are noob questions.

    I have a userform which I would not only like to declare variables for, but would also like to state what they stand for. Next, I would like to be able to refer back to them throughout the whole userform based off of Checkbox values. For example in declaring all variables in the userform:

    Please Login or Register  to view this content.

    Now, if a checkbox's value is true, I would like to make the above variables what they are declared above and place them into a text box. If they are false, I would like to make them blank (Var1 = "" for example). Lastly, when the checkbox value is false, I want to remove the specific variable's text out of the text box (making it ""). I have attempted to do this by using the following:

    Please Login or Register  to view this content.

    It's kind of like an on/off switch code for each checkbox. Place the veriable's text in the text box if checked, remove it (only that text box's verbiage) if unchecked, but leave all other checkbox verbiage in the text box.


    It is going to be labor intensive if I have to create 10 different checkbox true/false subs, on 7 different tabs, in this userform. From what I see, I am going to have to create a sub for every checkbox and include similar code, like the code above, to make this work with every single variable and checkbox. There is going to be 1 variable for every checkbox...for a total of 10 checkboxes per tab, 1 text box per tab, and about 7 tabs.

    Is there an easier way? Am I doing this completely wrong? Any help is greatly appreciated. Thank you.
    Last edited by HOT97ECLIPSEGSX; 06-20-2010 at 03:48 AM.

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Declaring specific userform variables/checkbox help

    What's the purpose of this?
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Registered User
    Join Date
    01-07-2010
    Location
    Dorothy and Todo Land, KS
    MS-Off Ver
    Office 2003 & 2007
    Posts
    34

    Re: Declaring specific userform variables/checkbox help

    I am creating something extremely useful at my job. It's helping me to advance within the company. If you could help me with the code I'm having trouble with I would greatly appreciate it.

    EDIT: If you would like a copy of the workbook so you can see what I am attempting to do, please let me know.

    Thanks.

    Dustin

  4. #4
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Declaring specific userform variables/checkbox help

    To best describe or illustrate your problem you would be better off attaching a dummy workbook, the workbook should contain the same structure and some dummy data of the same type as the type you have in your real workbook - so, if a cell contains numbers & letters in this format abc-123 then that should be reflected in the dummy workbook.

    If needed supply a before and after sheet in the workbook so the person helping you can see what you are trying to achieve.

    Doing this will ensure you get the result you need!

  5. #5
    Registered User
    Join Date
    01-07-2010
    Location
    Dorothy and Todo Land, KS
    MS-Off Ver
    Office 2003 & 2007
    Posts
    34

    Re: Declaring specific userform variables/checkbox help

    I have attached a dummy workbook for how I would like this to work. The user can check, uncheck, and then check, and the text stacks. What I want is for the checkbox's text to be removed when it is unchecked, and placed in the text box when checked. "Stacking" text is also a normal part of how this is going to work.

    Thanks again!
    Attached Files Attached Files
    Last edited by HOT97ECLIPSEGSX; 06-20-2010 at 05:28 AM.

  6. #6
    Registered User
    Join Date
    01-07-2010
    Location
    Dorothy and Todo Land, KS
    MS-Off Ver
    Office 2003 & 2007
    Posts
    34

    Re: Declaring specific userform variables/checkbox help

    I keep trying to come up with the code and I'm not getting the on-off results I want. Also, I keep getting "nothing but comments can appear after End Sub or End Property" error. There isn't anything after it in the sub. So frustrating.
    Last edited by HOT97ECLIPSEGSX; 06-20-2010 at 01:22 PM.

  7. #7
    Registered User
    Join Date
    01-07-2010
    Location
    Dorothy and Todo Land, KS
    MS-Off Ver
    Office 2003 & 2007
    Posts
    34

    Re: Declaring specific userform variables/checkbox

    One of the things I am trying to do is have instant results when the box is checked, and instant results when the box is unchecked. I seem to be unable to find code to do this within the userform.

    I don't want to have to click a cmdbutton to see changes. I want text placed into a text box when checked, and then only that specific checkbox's text removed when unchecked.

    Lastly, I see a lot of "Me".checkbox1 in coding. I do not understand what the "Me" does within VBA in excel. Is my dummy sheet completely wrong?

    Thank you for any help.

  8. #8
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Declaring specific userform variables/checkbox

    I think this might be something like what you want
    Please Login or Register  to view this content.

  9. #9
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Declaring specific userform variables/checkbox

    I do not understand what the "Me" does within VBA in excel. Is
    In ThisWorkbook module, Me refers to the workbook in which the code appears (i.e., ThisWorkbook)

    In a worksheet module, Me refers to the associated worksheet (and the worksheet is the default reference for range references)

    In a forms module, Me refers to the form
    Entia non sunt multiplicanda sine necessitate

  10. #10
    Registered User
    Join Date
    01-07-2010
    Location
    Dorothy and Todo Land, KS
    MS-Off Ver
    Office 2003 & 2007
    Posts
    34

    Re: Declaring specific userform variables/checkbox

    Thank you so much. The above code is working as I intend it to work.

    Now this may be a mooching question, but I do not understand part of the code. The fact that "it works" is not good enough for me. I like to understand "why" it works so I can use it for other forms and situations in the future.

    Would you mind explaining, or pointing me to a link for:

    Me and Not Me
    addVar and how it works with "i"

    Lastly, when I want to close a userform, is it ok to use "userform.Hide" to close it, or is it best to use "Unload Me"?

    EDIT: I posted after the above "Me" explanation. My confusion with the explanation is why do I have to declare "Me" for VBA to know I'm referring to that specific userform? I figure it is intelligent enough to understand the code I'm creating only corresponds to that particular form.
    Last edited by HOT97ECLIPSEGSX; 06-20-2010 at 05:15 PM.

  11. #11
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Declaring specific userform variables/checkbox

    You don't specifically need to use Me,it's just a good practise.

    The addVar is just a Procedure that works within the UserForm to add your value to the TextBox,the i is declared as an integer within the brackets of the Procedure. The value for i is added when the Procedure is called by selecting the CheckBox.

    You can Hide a form.

  12. #12
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Declaring specific userform variables/checkbox

    Hiding a form maintains the current contents when it is subsequently redisplayed in the same Excel session. Unloading resets it to its design-time values.

  13. #13
    Registered User
    Join Date
    01-07-2010
    Location
    Dorothy and Todo Land, KS
    MS-Off Ver
    Office 2003 & 2007
    Posts
    34

    Re: Declaring specific userform variables/checkbox

    Ok now I'm honestly getting irritated. Before I go any further, please know I appreciate all of the help everyone has provided in this thread. I'm almost finished with my questions.

    Only problem I'm having is I get a stupid "Only comments may appear after End Sub, End Function, or End Property."

    I do not have anything at ALL after any End Sub. VB separates each sub as it normally does with a solid line. I don't get it. I was so close, and I can't get this error to go away. The line of code it breaks on is when I click one of my check boxes in my non-dummy workbook. Example of the code:

    Please Login or Register  to view this content.

    Excel provides a yellow line where the code breaks. The yellow line is where the asterisks are above. It highlights that line in yellow, and then highlights the next sub's beginning title "private sub subname_click()" in blue. I don't get it.

  14. #14
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Declaring specific userform variables/checkbox

    What's ** for?

    The code didn't error in your test file
    Attached Files Attached Files

  15. #15
    Registered User
    Join Date
    01-07-2010
    Location
    Dorothy and Todo Land, KS
    MS-Off Ver
    Office 2003 & 2007
    Posts
    34

    Re: Declaring specific userform variables/checkbox

    You're right, it didn't. I copied the code directly over to my original and modified it by changing the declared variable names, then changing the checkbox sub variable names. The "**" are not in my actual code. I just put them here to show you where Excel was showing the error.

    I only get the error when I click the 2 functional checkboxes. The clear checkbox, clear note, and submit all work correctly.

  16. #16
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Declaring specific userform variables/checkbox

    If you have a problem then attach the workbook

+ 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