+ Reply to Thread
Results 1 to 21 of 21

Access Dynamic Labels in Userform Class Events in Excel VBA

  1. #1
    Registered User
    Join Date
    12-13-2020
    Location
    vskp, india
    MS-Off Ver
    windows10, office2007
    Posts
    35

    Access Dynamic Labels in Userform Class Events in Excel VBA

    i have one tabstrip with varying tabs. Each tab will have 3 dynamic labels. I have added dynamic labels with identical names corresponding to tab number and label number like "tsTab_lblNo" & x & "_" & n making visibility FALSE. Then added to existing mButtons public collection. Here I like to display the corresponding labels when clicked on a tab item. i understood tabstrip wont store controls. i tried in different ways but could not succeeded. Please help.
    Code is as follows. My tabs label code in module
    Please Login or Register  to view this content.
    Class event code
    Please Login or Register  to view this content.

  2. #2
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,911

    Re: Access Dynamic Labels in Userform Class Events in Excel VBA

    Quote Originally Posted by aprasad View Post
    Then added to existing mButtons public collection.
    No, you didn't. You added them to a local variable which is reset as soon as your routine ends.
    Rory

  3. #3
    Registered User
    Join Date
    12-13-2020
    Location
    vskp, india
    MS-Off Ver
    windows10, office2007
    Posts
    35

    Re: Access Dynamic Labels in Userform Class Events in Excel VBA

    Thank you Mr Rorya for your early reply. Sorry, i have not mentioned here but I have declared mButtons as New collection and ts_label As MSForms.Label only. Error is at line Controls("tsTab_lblNo" & Mytabstrip.Value & "_" & n).Visible = True in class Mytabstrip_Click(ByVal Index As Long) event, saying sub or function not defined. If possible please correct code

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

    Re: Access Dynamic Labels in Userform Class Events in Excel VBA

    You've declared mButtons within the sub test, as soon as that code stops running mButtons will be out of scope.
    If posting code please use code tags, see here.

  5. #5
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,911

    Re: Access Dynamic Labels in Userform Class Events in Excel VBA

    You also need to refer to mytabstrip.Controls since your class does not have a Controls property.

  6. #6
    Registered User
    Join Date
    12-13-2020
    Location
    vskp, india
    MS-Off Ver
    windows10, office2007
    Posts
    35

    Re: Access Dynamic Labels in Userform Class Events in Excel VBA

    Mr Norie and Rorya, Infact mButtons is declared as public variable in calling procedure Public mButtons As New Collection. Also I have tried with Mytabstrip.Controls("tsTab_lblNo" & Mytabstrip.Value & "_" & n).Visible = True in class code. But no result.
    1. Am I referring label in Collection correctly as Controls("tsTab_lblNo" & Mytabstrip.Value & "_" & n) ??
    2. Can one collection mButtons, be used for both buttons and labels ?

    Please guide
    Last edited by aprasad; 02-02-2021 at 12:34 PM. Reason: correcting

  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: Access Dynamic Labels in Userform Class Events in Excel VBA

    If you've already declared it publicly why are you declaring it again in 'test'?

  8. #8
    Registered User
    Join Date
    12-13-2020
    Location
    vskp, india
    MS-Off Ver
    windows10, office2007
    Posts
    35

    Re: Access Dynamic Labels in Userform Class Events in Excel VBA

    I will use it when running in current module, otherwise i will make it comment. just to understand. In addition to my earlier mentioned doubts, one more cropped up. will labels can be accessed by its name? If can't, can i get same display sequence with text boxes and how?

  9. #9
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,911

    Re: Access Dynamic Labels in Userform Class Events in Excel VBA

    Any control can be accessed by name.

  10. #10
    Registered User
    Join Date
    12-13-2020
    Location
    vskp, india
    MS-Off Ver
    windows10, office2007
    Posts
    35

    Re: Access Dynamic Labels in Userform Class Events in Excel VBA

    ok, noted. For easy understanding my problem, i have uploaded my sample excel file. Please suggest the changes.
    Attached Files Attached Files

  11. #11
    Registered User
    Join Date
    12-13-2020
    Location
    vskp, india
    MS-Off Ver
    windows10, office2007
    Posts
    35

    Re: Access Dynamic Labels in Userform Class Events in Excel VBA

    PS: project starts from Userform1.

  12. #12
    Registered User
    Join Date
    12-13-2020
    Location
    vskp, india
    MS-Off Ver
    windows10, office2007
    Posts
    35

    Re: Access Dynamic Labels in Userform Class Events in Excel VBA

    I expect problem is in referring mButtons collection or Controls in class events. I could not figure it out the syntax. Being a public variable mButtons collection is storing controls as required.
    May be the labels created are not linked with userform object. In local window of module code, label controls are visible, but when moved to class events (with userform Me) neither controls collection nor the added labels identified.
    Hope this makes my problem more understandable.

  13. #13
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,911

    Re: Access Dynamic Labels in Userform Class Events in Excel VBA

    Since you added the three labels to the userform, you'd need to refer to them in your tabstrip class handler using:

    Please Login or Register  to view this content.
    That will only work for the first 'page' of your tabstrip since you only have three labels.

  14. #14
    Registered User
    Join Date
    12-13-2020
    Location
    vskp, india
    MS-Off Ver
    windows10, office2007
    Posts
    35

    Re: Access Dynamic Labels in Userform Class Events in Excel VBA

    Thank you rorya. seems working, labels are behind the tabstrip, so need to do more. Can you say the reason to spell parent, 3 times? I have declared ctrl as object and retrieved labels from mButtons collection. But your single line code, looks more interesting. Please explain. Also how to bring front labels. Thank once again

  15. #15
    Registered User
    Join Date
    12-13-2020
    Location
    vskp, india
    MS-Off Ver
    windows10, office2007
    Posts
    35

    Re: Access Dynamic Labels in Userform Class Events in Excel VBA

    I have tried with zorder(0). But not success. I could not understand when default value of zorder for any control is 0, why it is being displayed backward showing? I think latest object will have 0 automatically. waiting for your guidance

  16. #16
    Registered User
    Join Date
    12-13-2020
    Location
    vskp, india
    MS-Off Ver
    windows10, office2007
    Posts
    35

    Re: Access Dynamic Labels in Userform Class Events in Excel VBA

    I have tried with textbox control also, but both labels and text boxes are hiding behind either multipage or tabstrip. How to make label/textbox bring front when tab1 clicked? please help

  17. #17
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,911

    Re: Access Dynamic Labels in Userform Class Events in Excel VBA

    You need to add the controls to the relevant container. For example, if you want the labels on a page of your multiframe, you should add them to that, not to the userform itself. You'll then need to amend the code I posted - the only reason it uses Parent three times is to get a reference back to the actual userform.

  18. #18
    Registered User
    Join Date
    12-13-2020
    Location
    vskp, india
    MS-Off Ver
    windows10, office2007
    Posts
    35

    Re: Access Dynamic Labels in Userform Class Events in Excel VBA

    Rorya, I have 3 labels/ textboxes for each Tabs( 5 tabs) of Tabstrip. On clicking of each tab, respective labels/texts should be displayed. I understood your suggestion. But could not able to implement. Error is 'object does not support this property/method". So again requesting for your correction. part of the module code is as follows.

    Please Login or Register  to view this content.
    Last edited by aprasad; 02-09-2021 at 12:40 PM. Reason: small adition of text

  19. #19
    Registered User
    Join Date
    12-13-2020
    Location
    vskp, india
    MS-Off Ver
    windows10, office2007
    Posts
    35

    Re: Access Dynamic Labels in Userform Class Events in Excel VBA

    rorya, somehere i read that tabstrip is not a container, if true, is it requires to define a frame to contain labels/textboxes? else where i am doing wrong in declaring labels/textboxes? Pl suggest code

  20. #20
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,911

    Re: Access Dynamic Labels in Userform Class Events in Excel VBA

    A tabstrip is not a container (I've always viewed them as more trouble than they're worth for precisely that reason). Therefore any controls need to be added to whatever contains the tabstrip - in your case that is a page of your multipage control, so that is where the controls need to be added.

  21. #21
    Registered User
    Join Date
    12-13-2020
    Location
    vskp, india
    MS-Off Ver
    windows10, office2007
    Posts
    35

    Re: Access Dynamic Labels in Userform Class Events in Excel VBA

    Sorry for delaying response. Thank you for your valuable suggestion and putting my code on track. I am obliged to thank you, Andy and Excelforum for my progress in my project.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Handling class events of userform from module code
    By aprasad in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-31-2021, 11:27 AM
  2. [SOLVED] Dynamic Userform with Multipage and Tabstrip events not firing
    By aprasad in forum Excel Programming / VBA / Macros
    Replies: 21
    Last Post: 01-22-2021, 03:53 AM
  3. [SOLVED] Class Module Events : How to refering to individual class members
    By kev_ in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-29-2020, 06:27 AM
  4. [SOLVED] Dynamic positions for textboxes/labels in userform
    By john55 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-03-2017, 08:52 AM
  5. how to place the dynamic labels in a table format on a userform
    By yoursamrit2000 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-23-2015, 02:20 AM
  6. [SOLVED] Userform & Dynamic Controls & Class Module
    By sarndt01 in forum Excel Programming / VBA / Macros
    Replies: 21
    Last Post: 09-18-2014, 01:53 PM
  7. [SOLVED] Dynamic userform. Problem with format, events and returning values
    By Claus in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-01-2005, 09:05 AM

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