Results 1 to 7 of 7
  1. #1
    New Lounger
    Join Date
    Jan 2001
    Location
    Arlington, Virginia, USA
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Changing User Form Caption

    I have a user form that has an option button that I want to change the caption based on the data in cell B2 on worksheet Sheet1. I want the caption to change on initialize form only.

  2. #2
    Uranium Lounger
    Join Date
    Jan 2001
    Location
    South Carolina, USA
    Posts
    7,295
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Changing User Form Caption

    The following should get you started:

    <pre>Private Sub UserForm_Initialize()
    If Sheet1.Range("B2").Value = "Something" Then
    Me.btnMyButton.Caption = "Something"
    Else
    Me.btnMyButton.Caption = "Something Else"
    End If
    End Sub
    </pre>


    This procedure goes in the event module that is behind the form that contains the button, not in a general module.
    Legare Coleman

  3. #3
    New Lounger
    Join Date
    Jan 2001
    Location
    Arlington, Virginia, USA
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Changing User Form Caption

    Legare,

    Thanks for the quick reply. Unfortunately, this locks me into a hard coded response of "Something" or "Something Else". What I wanted to do was change the value in cell B2 and have the code draw from that value. That will allow me to put a new name on the option button by changing the cell value.

  4. #4
    Uranium Lounger
    Join Date
    Jan 2001
    Location
    South Carolina, USA
    Posts
    7,295
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Changing User Form Caption

    I'm not sure that I understand what you are asking. What do you mean by "draw from that value?" If what you want to do is put the contents of cell B2 into the button caption, then you need something like this:

    <pre>Private Sub UserForm_Initialize()
    Me.btnMyButton.Caption = Sheet1.Range("B2").Value
    End Sub

    </pre>


    f that is not what you mean, then can you try to explain exactly what you want to do.
    Legare Coleman

  5. #5
    New Lounger
    Join Date
    Jan 2001
    Location
    Arlington, Virginia, USA
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Changing User Form Caption

    I had tried this before and I get a run-time error '424'.

  6. #6
    Uranium Lounger
    Join Date
    Jan 2001
    Location
    South Carolina, USA
    Posts
    7,295
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Changing User Form Caption

    Some possible causes of this error are:

    1- The code was not being run as a result of the initilize event and therefore Me was not defined.

    2- The button name you used was not valid.

    3- The sheet name you used was not valid.
    Legare Coleman

  7. #7
    New Lounger
    Join Date
    Jan 2001
    Location
    Arlington, Virginia, USA
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Changing User Form Caption

    Got it, one letter off on the button name. Thanks for the help.

Posting Permissions

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