controls cut/paste

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • questionit
    Contributor
    • Feb 2007
    • 553

    #1

    controls cut/paste

    If you have many controls on a Tab Control and all of them have code written for them.

    Now if you want to move these controls from Tab Control to some other part of the form then the code for them will be dis-associated from them.

    If you want to associate the code again with the control, it has be done manually by clicking on control's event and it will be done.

    but this way, each control has to be done one by one... is there any one when you cut/paste controls from TabControl to some other place, the code remain associated with them ?
  • missinglinq
    Recognized Expert Specialist
    • Nov 2006
    • 3533

    #2
    Sorry, no! You can select multiple controls and do a some of things to them, such a change the font/color/attributes, but you can't multi-select and change properties that involve going into the code editor, which is what yu need to do to re-associate them with their code.

    Linq

    Comment

    • ADezii
      Recognized Expert Expert
      • Apr 2006
      • 8834

      #3
      Originally posted by questionit
      If you have many controls on a Tab Control and all of them have code written for them.

      Now if you want to move these controls from Tab Control to some other part of the form then the code for them will be dis-associated from them.

      If you want to associate the code again with the control, it has be done manually by clicking on control's event and it will be done.

      but this way, each control has to be done one by one... is there any one when you cut/paste controls from TabControl to some other place, the code remain associated with them ?
      Try modifying the OnClick() Event of all Controls on the Form as in:
      [CODE=vb]
      Dim ctl As Control

      For Each ctl In Me.Controls
      If ctl.OnClick = "" Then
      ctl.OnClick = "[Event Procedure]"
      End If
      Next[/CODE]

      Comment

      • missinglinq
        Recognized Expert Specialist
        • Nov 2006
        • 3533

        #4
        Excellent hack, ADezii! I'll put it in my references and give you credit if I post it anywhere!

        Linq ;0)>

        Comment

        • ADezii
          Recognized Expert Expert
          • Apr 2006
          • 8834

          #5
          Originally posted by missinglinq
          Excellent hack, ADezii! I'll put it in my references and give you credit if I post it anywhere!

          Linq ;0)>
          Still bumping into each other, old pal. Of course the previous code is only good for the Click() Event, and it doesn't Filter for Control Type or anything else. It was just meant to possibly point the OP in the right direction. See you around town!

          Comment

          • NeoPa
            Recognized Expert Moderator MVP
            • Oct 2006
            • 32669

            #6
            Originally posted by questionit
            If you have many controls on a Tab Control and all of them have code written for them.

            Now if you want to move these controls from Tab Control to some other part of the form then the code for them will be dis-associated from them.

            If you want to associate the code again with the control, it has be done manually by clicking on control's event and it will be done.

            but this way, each control has to be done one by one... is there any one when you cut/paste controls from TabControl to some other place, the code remain associated with them ?
            Question asked well.
            I may not be very helpful as I'm not sure of this, but I would try selecting them all and dragging them to where you want them on the main part of the form. That may well leave the links associated which wouldn't happen with a cut or copy.
            Good luck.

            Comment

            • ADezii
              Recognized Expert Expert
              • Apr 2006
              • 8834

              #7
              Originally posted by NeoPa
              Question asked well.
              I may not be very helpful as I'm not sure of this, but I would try selecting them all and dragging them to where you want them on the main part of the form. That may well leave the links associated which wouldn't happen with a cut or copy.
              Good luck.
              Hello NeoPa. I don't think that dragging individual Controls from Pages within a Tab Control to a Main Form will work. It's the same concept as attempting to drag Option Buttons out of their Group Container - they are confined to the Container Area and cannot escape it. Just some useless information you may want to know.

              Comment

              • missinglinq
                Recognized Expert Specialist
                • Nov 2006
                • 3533

                #8
                Understood, ADezii! A lot of people have learned how to loop thru controls, but I see mistakes all the time where they haven't specified what kind of controls to loop thru! Still an excellent template for changing these types of properties in this situation. BTW, vis a vis "bumping into each other;" we're both in the same time zone! I'm down the road in Richmond (Virginia, that is, not England!)

                And he's right, NeoPa. If you select the controls and try to drag them to the main body of the form, all you do is increase the size of the tabbed pages, because they are, in fact, contained by the tab control.

                Linq ;0)>

                Comment

                • NeoPa
                  Recognized Expert Moderator MVP
                  • Oct 2006
                  • 32669

                  #9
                  Thanks for coming back with those boys. I don't intend to mislead and I'd rather know if I get things wrong :)
                  QuestionIt, let us know if you manage to get the other (ADezii) suggested method to work for you (and how much that helped).

                  Comment

                  • questionit
                    Contributor
                    • Feb 2007
                    • 553

                    #10
                    Thanks for your answers

                    But being a beginner in VB, i am not very sure how to use the suggested code.

                    The code is just assigning same event procedure to each control on the form !?

                    and you meant to say that code would need to be added in every event procedure seperately?


                    Originally posted by NeoPa
                    Thanks for coming back with those boys. I don't intend to mislead and I'd rather know if I get things wrong :)
                    QuestionIt, let us know if you manage to get the other (ADezii) suggested method to work for you (and how much that helped).

                    Comment

                    • missinglinq
                      Recognized Expert Specialist
                      • Nov 2006
                      • 3533

                      #11
                      After you've moved your command buttons from the tabbed page to where ever you want them:
                      Place a button on your form
                      When the wizard pops up hit Cancel
                      Goto Properties - Events and double-click to the right of the OnClick box
                      Click on the ellipsis (...)
                      In the Command_Click sub that comes up for the button you just made, paste in ADezii's code.
                      Exit the code window
                      Run your form
                      Click on the button you just made.
                      If you've followed all of these instructions, all of the buttons you've moved should now be functioning.
                      Delete the button you just made from your form.

                      Comment

                      • questionit
                        Contributor
                        • Feb 2007
                        • 553

                        #12
                        That thing is good !!

                        but in the code line:
                        [code=vb]
                        ctl.OnClick = "[Event Procedure]"
                        [/code]

                        we are assigning "[Event Procedure]" to all the controls. Whats the value of "[Event Procedure]" ?

                        it looks like that sameevent procedure is being assigned to all the controls, but actually not... how does that work then?



                        Originally posted by missinglinq
                        After you've moved your command buttons from the tabbed page to where ever you want them:
                        Place a button on your form
                        When the wizard pops up hit Cancel
                        Goto Properties - Events and double-click to the right of the OnClick box
                        Click on the ellipsis (...)
                        In the Command_Click sub that comes up for the button you just made, paste in ADezii's code.
                        Exit the code window
                        Run your form
                        Click on the button you just made.
                        If you've followed all of these instructions, all of the buttons you've moved should now be functioning.
                        Delete the button you just made from your form.

                        Comment

                        • NeoPa
                          Recognized Expert Moderator MVP
                          • Oct 2006
                          • 32669

                          #13
                          What you say makes sense - but in this case is actually wrong. The string "Event Procedure" is actually the exact value for that property. This is what it contains when the event procedure is linked to that event. Otherwise it could be empty, or have a macro as its value.
                          Does this make sense?

                          Comment

                          • questionit
                            Contributor
                            • Feb 2007
                            • 553

                            #14
                            NeoPa

                            that makes sence..

                            so the string " Event Procedure" is like a buffer.. whenevr we associate any procedure to any control ... the link to that code is stored in "Event Procedure" .. is this what it is ?

                            but even it is working like this... it is strange that assigning just "Event Procedure" to controls actually associated the right code with every control !



                            Originally posted by NeoPa
                            What you say makes sense - but in this case is actually wrong. The string "Event Procedure" is actually the exact value for that property. This is what it contains when the event procedure is linked to that event. Otherwise it could be empty, or have a macro as its value.
                            Does this make sense?

                            Comment

                            • NeoPa
                              Recognized Expert Moderator MVP
                              • Oct 2006
                              • 32669

                              #15
                              Not quite right there.
                              The string "Event Procedure" is stored in the property of the object with the same name as the event. So, a CommandButton would have a Click event (to handle what happens when it is clicked), so it would also have a Click property (Look in design view and see in the properties various properties with the names of events). When there is VBA code for a particular event (in this case Click), that similarly named property contains the string "Event Procedure".
                              Does that make more sense. It's an ADezii Clever. He's a clever chap and comes up with various work-arounds that most of us have never thought of :)

                              Comment

                              Working...