Results 1 to 6 of 6
  1. #1
    2 Star Lounger
    Join Date
    Mar 2002
    Location
    Germany, Germany
    Posts
    169
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Calling UserForms from different points (XP SP1)

    Hello everybody!

    I have a userform, which shows up by pressing two different buttons. Now I want the userform to know which button was pressed to call the userform. Is there a way to realize this? I could think about a workaround with setting a global variable to a certain value by pressing the button and then evaluate this variable within the userform-macros. But could anybody think about a more elegant solution?
    I am really curious, if somebody has an idea.

    Best regards, Porley

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 28 Times in 28 Posts

    Re: Calling UserForms from different points (XP SP1)

    What kind of buttons are you using to open the userform?
    1) Buttons on a worksheet from the Forms toolbar.
    2) Buttons on a worksheet from the Control Toolbox.
    3) Buttons on another userform.

  3. #3
    2 Star Lounger
    Join Date
    Mar 2002
    Location
    Germany, Germany
    Posts
    169
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Calling UserForms from different points (XP SP

    Hello Hans!

    Sorry for forgetting this information. I have placed two Buttons from the Control Toolbox within a worksheet. Both call the same userform (simply by Userform1.show). Now I want the userform to know, which button was pressed.

    Best regards, Porley

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 28 Times in 28 Posts

    Re: Calling UserForms from different points (XP SP

    You could use a public variable defined in the userform module instead of a variable defined globally in a standard module:

    Public strCaller As String

    You can set this in the On Click code of the command buttons:

    Private Sub CommandButton1_Click()
    Load UserForm1
    UserForm1.strCaller = "CommandButton1"
    UserForm1.Show
    End Sub

    Note: if you had used command buttons from the Forms toolbar, you could have used Application.Caller in the code behind the userform. This property would have held the name of the command button that was clicked to open the userform.

  5. #5
    2 Star Lounger
    Join Date
    Mar 2002
    Location
    Germany, Germany
    Posts
    169
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Calling UserForms from different points (XP SP

    Dear Hans,

    I have tested your idea, and it works perfectly well. Thank you very much! I did not know that you may define public variables in forms and that they somehow show up like properties. So thanks again!

    Best regards, Porley

  6. #6
    WS Lounge VIP sdckapr's Avatar
    Join Date
    Jul 2002
    Location
    Pittsburgh, Pennsylvania, USA
    Posts
    11,225
    Thanks
    14
    Thanked 342 Times in 335 Posts

    Re: Calling UserForms from different points (XP SP

    Another option is to dimension as the command button object
    <pre>Public CMB As CommandButton</pre>


    Then use
    <pre> Set CMB = CommandButton1</pre>



    Then the userform can work directly with the object and its properties.

    Steve

Posting Permissions

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