+ Reply to Thread
Results 1 to 7 of 7

Dynamically load Userform Label and textbox if name elegible

  1. #1
    Forum Expert nigelog's Avatar
    Join Date
    12-14-2007
    Location
    Cork, Ireland
    MS-Off Ver
    Office 365 Windows 10
    Posts
    2,286

    Dynamically load Userform Label and textbox if name elegible

    I would like to load names of personnel holding valid site permits on userform initialize taking data from a worksheet - using a piece of code I was looking at on this site earlier what changes would I have to make to load a text box beside each label.. desired output is in workbook attached. Any help appreciated

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by nigelog; 01-27-2017 at 07:00 AM.

  2. #2
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,481

    Re: Dynamically load Userform Label and textbox if name elegible

    Hi again,

    Take a look at the dynamic UserForm in the attached workbook and see if it does what you need.

    The UserForm uses the following code:

    Please Login or Register  to view this content.

    You'll see that the basic UserForm contains only the three Site labels (without meaningful captions) and a single Exit CommandButton - all of the other controls (Labels and TextBoxes) are generated and populated dynamically on the basis of the information contained in the Employee Data table on the Data worksheet,


    Hope this helps - as always, please let me know how you get on.

    Regards,

    Greg M
    Attached Files Attached Files

  3. #3
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Dynamically load Userform Label and textbox if name elegible

    Hi nigelog,

    I didn't look at Greg's solution, but here is something else for you to look at. I prefer to have most of my code in an ordinary code module. It is a matter of personal preference. It makes the UserForm code smaller, and allows me to find the UserForm event handlers sooner.

    It is a best practice to declare all variables. If you misspell a variable in your code, VBA will silently assume it is a Variant variable and go on executing with no clue to you that you have a bug. Go to the VBA development window, click Tools, Options, and check "Require Variable Declaration." This will insert the following line at the top of all new modules:
    Please Login or Register  to view this content.
    This option requires all variables to be declared and will give a compiler error for undeclared variables.

    In the UserForm Code Module:
    Please Login or Register  to view this content.
    In Ordinary Code Module Module1:
    Please Login or Register  to view this content.
    Lewis

  4. #4
    Forum Expert nigelog's Avatar
    Join Date
    12-14-2007
    Location
    Cork, Ireland
    MS-Off Ver
    Office 365 Windows 10
    Posts
    2,286

    Re: Dynamically load Userform Label and textbox if name elegible

    Thankyou both for your very accurate replies. I went with the former solution as I was more familiar with the layout. I have adapted the code to suit the 6 sites I require and only have one problem. I cant seem to invoke the "warning days" change of format to red. I have changed the number of days but as yet have found why not activating


    SORTED - my fault - have incorporated all into main file menu and works perfectly. Many thanks again. Will use this format to sort a few other displays....
    Attached Files Attached Files
    Last edited by nigelog; 01-27-2017 at 05:55 AM.

  5. #5
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,481

    Re: Dynamically load Userform Label and textbox if name elegible

    Hi again,

    Many thanks for your feedback and also for posting the final version of your workbook - looks impressive!

    You're welcome - glad I was able to help.

    Regards,

    Greg M

  6. #6
    Forum Expert nigelog's Avatar
    Join Date
    12-14-2007
    Location
    Cork, Ireland
    MS-Off Ver
    Office 365 Windows 10
    Posts
    2,286

    Re: Dynamically load Userform Label and textbox if name elegible

    Hi Greg, used the auto upload code to negate the need for adding new names to original menu when updated. Just need now to create code to amend details or add new drivers to driver details sheet. Thanks for the pointers on this. Has been a worthwhile update of an old menu - have to also work out format issue with warnings date....
    Attached Files Attached Files
    Last edited by nigelog; 01-30-2017 at 05:59 AM.

  7. #7
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,481

    Re: Dynamically load Userform Label and textbox if name elegible

    Hi again,

    Many thanks for posting this and also for your private message.

    Your original UserForm is looking pretty fancy at this stage - well done!

    It's been very interesting for me to follow how your projects have developed - most times I post a solution, get a quick thank-you reply (sometimes not even that! ), and that's the end of the story, so many thanks for keeping me updated.

    Let me know if there's anything else you think I can help you with.

    Best regards,

    Greg M

+ 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. UserForm: Textbox value load according to drop down list
    By lazyserv in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 05-31-2015, 05:00 PM
  2. [SOLVED] Excel 2010 - Userform - display date from textbox in a label or textbox in 'ddd' format
    By theshybutterfly in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-29-2015, 10:54 PM
  3. Replies: 11
    Last Post: 01-20-2015, 09:34 AM
  4. [SOLVED] changing userform label control's color dynamically
    By Ouka in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-30-2014, 02:26 AM
  5. Use variable as name for label in userform, dynamically update different labels
    By seaofgreen in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-09-2013, 04:12 PM
  6. [SOLVED] Load last cell in Column C to Userform Textbox
    By Nu2Java in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-25-2012, 10:22 AM
  7. userform: trasnferring textbox value to label field in next userform
    By brillison in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 07-17-2008, 08:18 PM

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