By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,560 Members | 949 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,560 IT Pros & Developers. It's quick & easy.

controls cut/paste

100+
P: 553
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 ?
Aug 4 '07 #1
Share this Question
Share on Google+
16 Replies


missinglinq
Expert 2.5K+
P: 3,532
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
Aug 4 '07 #2

ADezii
Expert 5K+
P: 8,669
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:
Expand|Select|Wrap|Line Numbers
  1. Dim ctl As Control
  2.  
  3. For Each ctl In Me.Controls
  4.   If ctl.OnClick = "" Then
  5.     ctl.OnClick = "[Event Procedure]"
  6.   End If
  7. Next
Aug 4 '07 #3

missinglinq
Expert 2.5K+
P: 3,532
Excellent hack, ADezii! I'll put it in my references and give you credit if I post it anywhere!

Linq ;0)>
Aug 4 '07 #4

ADezii
Expert 5K+
P: 8,669
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!
Aug 4 '07 #5

NeoPa
Expert Mod 15k+
P: 31,602
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.
Aug 4 '07 #6

ADezii
Expert 5K+
P: 8,669
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.
Aug 5 '07 #7

missinglinq
Expert 2.5K+
P: 3,532
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)>
Aug 5 '07 #8

NeoPa
Expert Mod 15k+
P: 31,602
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).
Aug 5 '07 #9

100+
P: 553
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?


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).
Aug 5 '07 #10

missinglinq
Expert 2.5K+
P: 3,532
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.
Aug 5 '07 #11

100+
P: 553
That thing is good !!

but in the code line:
Expand|Select|Wrap|Line Numbers
  1.     ctl.OnClick = "[Event Procedure]"
  2.  
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?



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.
Aug 6 '07 #12

NeoPa
Expert Mod 15k+
P: 31,602
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?
Aug 6 '07 #13

100+
P: 553
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 !



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?
Aug 6 '07 #14

NeoPa
Expert Mod 15k+
P: 31,602
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 :)
Aug 6 '07 #15

ADezii
Expert 5K+
P: 8,669
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 :)
Hello NeoPa:
Not being critical or nit-picky but clarifying something. For Events having corresponding Event Properties, the Event Properties are prefaced by On as in:
Expand|Select|Wrap|Line Numbers
  1. Event            Associated Property
  2. Click            On Click
  3. MouseDown        On MouseDown
  4. KeyPress         On KeyPress
  5. ...                       ...
  6.  
BTW, like the clever chap comment - only wish it were true! See you around, Old Chap!
Aug 6 '07 #16

NeoPa
Expert Mod 15k+
P: 31,602
Hello NeoPa:
Not being critical or nit-picky but clarifying something. For Events having corresponding Event Properties, the Event Properties are prefaced by On as in:
Expand|Select|Wrap|Line Numbers
  1. Event            Associated Property
  2. Click            On Click
  3. MouseDown        On MouseDown
  4. KeyPress         On KeyPress
  5. ...                       ...
  6.  
BTW, like the clever chap comment - only wish it were true! See you around, Old Chap!
Hi ADezii.

I'm going to be critical and nit-picky here (:D) and say that while that is true for a number of events it is not true for all (Before/After Update et al). It was a point worth making but I would say that, if the property is not named exactly the same then it should at least be recognisably similar.

Now don't argue with me. You ARE a clever chap :)
Aug 7 '07 #17

Post your reply

Sign in to post your reply or Sign up for a free account.