Change Caption Of Label & UserForm

  • I present a form (a calendar) twice in my routine to the user but I want to change the Caption of the Label on each pass?


    The first time it's displayed: 'Please select a start date' (calendar closes & goes off and does stuff)
    ... and on the 2nd display: 'Please select an end date'.

    Any hints on how best to do this please?

    Thank you,
    Andy :thanx:

  • Re: Change Caption Of Label In Form

    Hi Andy,

    This should be pretty easy...

    If you want to change the caption on a userform that the calendar control is inserted on (say the userform is called UserForm1) then use;

    UserForm1.Caption = "Whatever the title should be"

    The other way would be to insert a label in the userform and have that changing value (if Label was called Label1);

    UserForm1.Label1.Caption = "Whatever the title should be"

    Or you could have a msgbox pop up before the form to say which date they should enter...there's lots of ways...

    Hope that helps. Let me know if you need something more specific.

  • Re: Change Caption Of Label In Form

    Thanks for your reply; perhaps I should have been more specific.

    I'm happy with how you define a label - eg:

    UserForm1.Label1.Caption = "text in here"

    .. but essentially where should I toggle this on and off?

    I was thinking along the lines of:
    1. Define label first time round
    2. Show calendar
    3. Exit calendar (do other stuff)
    4. Define label for the 2nd time
    5. Show calendar (with label as set in step 4)

    Should it be done in its own sub-routine (ie in a module) or in the UserForm code itself, etc.?


  • Re: Change Caption Of Label In Form

    Hi ANdy,

    Maybe you need to send an example because I don't think I'm getting why this is a problem...

    You can change the caption of a label at anytime as long as you have loaded the userform the label sits on (you don't even need to hide the form to do so).

    But if you want it to change just use the same line of code, just before you show the form for the second time, e.g.

    Hope that's better.

  • Re: Change Caption Of Label In Form

    The difficulty I see is getting the userform to "remember" which caption was used for the previous instance of the UF.
    This is one way

  • Re: Change Caption Of Label In Form

    I've worked it out, by doing:

    Not sure how good this is programatically but it works!

  • Re: Change Caption Of Label In Form

    I only need to show the form twice fortunately; that's why I chose a boolean value.

    Andy[hr]*[/hr] Auto Merged Post Until 24 Hrs Passes;[dl]*[/dl]I've refined it slightly:

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!