Results 1 to 18 of 18

Thread: [RESOLVED] Need Help with ActiveX Command Button (Return Click Event)

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2021
    Posts
    59

    Resolved [RESOLVED] Need Help with ActiveX Command Button (Return Click Event)

    Hi Everyone!

    Sorry!

    I feel ... Out of phase !!

    But I have this problem which I cannot solve.

    I don't find any information about it, and I don't understand how I can do it.
    If you don't know the proper commands, you can't proceed, then !!


    How do you get the return of the Click event, from a button inserted in a UserControl, on a common User Form!?

  2. #2
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Re: Need Help with ActiveX Command Button (Return Click Event)

    There is a control interface wizard in vb6 that will help you with this.

  3. #3

    Thread Starter
    Member
    Join Date
    Mar 2021
    Posts
    59

    Re: Need Help with ActiveX Command Button (Return Click Event)

    Let me explain, maybe I have not made it correctly!
    (Sorry for the delay in replying ...)

    Therefore:

    I have created a UserControl, on which there is also a 'CommandButton'.
    Once the control is created, if I insert it in a common program (on a normal Form), I can only make it do things that I have set in the UserControl code ...

    But how can I get the action to happen (act) on the Form itself !?
    (Without, perhaps, having to use an Event Timer to verify it !?)

  4. #4
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: Need Help with ActiveX Command Button (Return Click Event)

    Events do not bubble from constituent controls up through the UserControl's interface.

    If you want such a thing the UserControl should declare a Public Event of its own, and when the command button Click event occurs your UserControl code should handle it, calling RaiseEvent for your newly defined event. This new event can be handled in the parent Form of an instance of your UserControl.

    Pretty basic stuff, all covered in the VB6 documentation.

  5. #5
    PowerPoster
    Join Date
    Feb 2017
    Posts
    5,064

    Re: Need Help with ActiveX Command Button (Return Click Event)

    Code:
    Public Event Click()
    
    Private Sub Command1_Click()
        RaiseEvent Click
    End Sub

  6. #6
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Re: Need Help with ActiveX Command Button (Return Click Event)

    The wizard I mentioned makes it easy to add the code for the events. You should at least take a look at it if you are trying to create a user control and do not know how to map events or properties from controls contained there in.

  7. #7
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: Need Help with ActiveX Command Button (Return Click Event)

    The wizard isn't a bad thing, but more something you'd use as training wheels in a intro course rather than in real programs. Of course you can always start with the wizard's output and from there do a lot of "trimming, filing, sanding, polishing, varnishing, etc." to clean it up. It tends to produce a pretty rough Fred Flintstone Car a long way from a Nissan, Ford, or even a Kia. Forget about a Honda or Toyota.

    Or a better analogy might be a Soap Box Derby car. Great to learn on, not so much though if you don't want to get fired.

  8. #8

    Thread Starter
    Member
    Join Date
    Mar 2021
    Posts
    59

    Re: Need Help with ActiveX Command Button (Return Click Event)

    Dilettante...

    First of all, thank you for the reply.
    But I take you back on something you said:

    Pretty basic stuff, all covered in the VB6 documentation.
    There is always to consider that there are those who do not do these things (or do not know them!)
    as a job, but that it is a simple hobby (someone tries it from time to time), programming!
    For sure it will be easy stuff, for those who are aware of it, but for those who are fasting, and learn self-taught, it is not easy (obviously, it would be 'to read ALL the documentation', but you don't always have the time to do it; therefore, an alternative solution is sought: help! Not always one does it because it is easier for them to have the code 'cooked and eaten' !!)

    Don't take it as a controversy; I just wanted to point this out as fact!

    I hope with this, you will want to help me in the future if I need it !!!
    ----------------------

    Eduardo ...
    Thank you too!

    Anyway, what you suggested to me, I had tried it, but obviously, I must have done something wrong, because I was unable to continue...


    Now I want to try again, and understand how these commands also return the Click ...

    I'll let you know!

  9. #9

    Thread Starter
    Member
    Join Date
    Mar 2021
    Posts
    59

    Re: Need Help with ActiveX Command Button (Return Click Event)

    Ah!!!

    And sorry DataMiser ...

    It's not that I haven't considered your answer ...
    And that I didn't understand how it was to be done!

    Give me 'way to settle' !!!

    (I'm a LITTLE fasting with these ActiveX commands!)

  10. #10
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Re: Need Help with ActiveX Command Button (Return Click Event)

    Load your control in the designer. Go to addins - addin manager. Load the vb6 activex ctrl interface wizard. then go to addins and select the wizard. It will allow you to select propertes and methods that will be exposed by your control then it will allow you to define custom properties and methods if needed and then it will allow you to map properties and methods to those of controls in your user control. Once you have made your selections it will generate the required code.

    Once you have completed the wizard you can look at the code behind your control and see how it has mapped the events and properties to get a better understanding of how this is done.

    Of course it is not always ideal but it does generate working code and can be used to save a bit of time and headaches, especially for those who do not have a firm grasp on control creation.
    .

  11. #11

    Thread Starter
    Member
    Join Date
    Mar 2021
    Posts
    59

    Re: Need Help with ActiveX Command Button (Return Click Event)

    DataMiser ...

    You see, sometimes talking is always useful (rather than going 'for certain' !!)

    NO!
    I haven't solved what I wanted yet ...
    But you made me discover something that I didn't know, and that I was wondering how it could be done ...
    And now I know!

    In its own way this Wizard is useful, I don't know why Dilettant said that there is 'such a bad thing', most likely, there will be much more, as a methodology, that could be more advanced; however, for now, I manage like this!
    (It is useful to me in some way!)


    Anyway to return to the Click event

    What just escapes me is how I can get 'the return' ...
    Unfortunately, if I don't understand this, I can't go on.

  12. #12
    PowerPoster
    Join Date
    Feb 2017
    Posts
    5,064

    Re: Need Help with ActiveX Command Button (Return Click Event)

    Quote Originally Posted by ProgyReloaded View Post
    What just escapes me is how I can get 'the return' ...
    Unfortunately, if I don't understand this, I can't go on.
    What do you mean "the return"?

    It is very easy to get the click event.
    See the project attached.
    Attached Files Attached Files

  13. #13

    Thread Starter
    Member
    Join Date
    Mar 2021
    Posts
    59

    Re: Need Help with ActiveX Command Button (Return Click Event)

    Not so simple!

    Now I make a scheme!

  14. #14

    Thread Starter
    Member
    Join Date
    Mar 2021
    Posts
    59

    Re: Need Help with ActiveX Command Button (Return Click Event)

    Like this!
    Attached Images Attached Images   
    Last edited by ProgyReloaded; Apr 28th, 2021 at 12:07 PM.

  15. #15
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Re: Need Help with ActiveX Command Button (Return Click Event)

    I am not sure where you are stuck. The code in post #5 is all you really need to relay the click event.
    On your parent form you will have a click event for the usercontrol. That event will fire when the button is clicked.

    It really is that simple.

    Now if you already have a click event that is mapped to the usercontrol itself then you need a different name for the button click event.
    Code:
    Public Event ButtonClick()
    
    Private Sub Command1_Click()
        RaiseEvent ButtonClick
    End Sub
    This code of course would be in the user control.
    When the control added to a form then you will have a UserControl1_ButtonClick() event where you would place whatever code you want to execute when the button on the control is clicked just like you would any other control.

  16. #16
    PowerPoster
    Join Date
    Feb 2017
    Posts
    5,064

    Re: Need Help with ActiveX Command Button (Return Click Event)

    You don't need to compile the ocx to test, you can make a project group.
    Check the test in the attached sample, open Group1.vbg
    Attached Files Attached Files

  17. #17

    Thread Starter
    Member
    Join Date
    Mar 2021
    Posts
    59

    Re: Need Help with ActiveX Command Button (Return Click Event)

    I have no words...
    I have no words... !!!

    So Eduardo:
    I do not know what to tell you.
    It is absolutely as you said.

    I was creating two example programs, to prove it didn't work ...
    And I was left like a fool to see it going!

    Things to go crazy !!!


    I made it easier, to see where I was wrong; so I made a comparison with my program (which still didn't work).


    I had to delete a part of the code, and try to rewrite it from scratch, because I just couldn't.

    So, I must imagine that it was simply some writing error, because the thing is absurd!


    Anyway, given the example I was giving, the way I composed it ...
    (Which is not very different from what you said, but in the process of which, I thought something varied)


    Anyway, I want to thank you for your availability!
    There is always a need for a hand !!!
    Attached Files Attached Files

  18. #18
    PowerPoster
    Join Date
    Feb 2017
    Posts
    5,064

    Re: [RESOLVED] Need Help with ActiveX Command Button (Return Click Event)

    OK, glad you could work it out.

Posting Permissions

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



Click Here to Expand Forum to Full Width