How to associate control events when copying controls

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a flakey form with many controls and their events.

I have set up a new form and have copied the controls and code to it and of
course the events have been lost.

Any way of associating the events with the controls easily.
 
Hi Thomas,

go to the code behind your first form -- copy the relevant
event procedures to the code behind your second form. The,
go to each control individually to ensure that the proper
event says [Event Procedure] -- if it does not, choose
[Event Procedure] and click on the builder button (...) to
the right -- if it takes you to just a prcedure declaration
and and End Sub, you still need to copy the code from the
first form.


Whenever you write or paste code, your should ALWAYS compile
it before you attempt to run it.

from the menu: Debug, Compile

fix any errors on the yellow highlighted lines

keep compiling until nothing happens (this is good!)

Warm Regards,
Crystal
Microsoft Access MVP 2006

*
Have an awesome day ;)

remote programming and training
strive4peace2006 at yahoo.com

*
 
Thanks but I know all that.

I have many many controls and events. Please tell me that I can do this
automatically somehow or programatically or even magically. Manually would
take a long time and errors would result that would not be picked up for a
long time etc etc. Um does anyone understand the real issues?

--
Regards
Tom


strive4peace" <"strive4peace2006 at yaho said:
Hi Thomas,

go to the code behind your first form -- copy the relevant
event procedures to the code behind your second form. The,
go to each control individually to ensure that the proper
event says [Event Procedure] -- if it does not, choose
[Event Procedure] and click on the builder button (...) to
the right -- if it takes you to just a prcedure declaration
and and End Sub, you still need to copy the code from the
first form.


Whenever you write or paste code, your should ALWAYS compile
it before you attempt to run it.

from the menu: Debug, Compile

fix any errors on the yellow highlighted lines

keep compiling until nothing happens (this is good!)

Warm Regards,
Crystal
Microsoft Access MVP 2006

*
Have an awesome day ;)

remote programming and training
strive4peace2006 at yahoo.com

*
I have a flakey form with many controls and their events.

I have set up a new form and have copied the controls and code to it and of
course the events have been lost.

Any way of associating the events with the controls easily.
 
Tom, I think your issue is that when you paste the controls, some of the
event properties are not set, even though there is code for those events in
the form's module, and so the code does not execute?

If so, try this:
1. Select all the code in the form's module (Ctrl+A.)
2. Cut to clipboard (Ctrl+X.)
3. Paste back into the empty module (Ctrl+V.)

Does Access set all the event properties for you when you do this? My
recollection is that it does.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

ThomasAJ said:
Thanks but I know all that.

I have many many controls and events. Please tell me that I can do this
automatically somehow or programatically or even magically. Manually would
take a long time and errors would result that would not be picked up for a
long time etc etc. Um does anyone understand the real issues?

--
Regards
Tom


strive4peace" <"strive4peace2006 at yaho said:
Hi Thomas,

go to the code behind your first form -- copy the relevant
event procedures to the code behind your second form. The,
go to each control individually to ensure that the proper
event says [Event Procedure] -- if it does not, choose
[Event Procedure] and click on the builder button (...) to
the right -- if it takes you to just a prcedure declaration
and and End Sub, you still need to copy the code from the
first form.


Whenever you write or paste code, your should ALWAYS compile
it before you attempt to run it.

from the menu: Debug, Compile

fix any errors on the yellow highlighted lines

keep compiling until nothing happens (this is good!)

Warm Regards,
Crystal
Microsoft Access MVP 2006

*
Have an awesome day ;)

remote programming and training
strive4peace2006 at yahoo.com

*
I have a flakey form with many controls and their events.

I have set up a new form and have copied the controls and code to it
and of
course the events have been lost.

Any way of associating the events with the controls easily.
 
Correct. I thought this was an MS classic 'by design' (er feature would you
believe) whereby the code associated with a control is not copied/pasted. I
read this in the MS KB some time back but could not find it this time.

I created a blank form (form B) and FIRST copied ALL the code from the
original form (form A) into 'form B'.
Then I C&Ped ALL the controls from 'form A' into 'form B' but ALL the
appropriate events were not set.

--
Regards
Tom


Allen Browne said:
Tom, I think your issue is that when you paste the controls, some of the
event properties are not set, even though there is code for those events in
the form's module, and so the code does not execute?

If so, try this:
1. Select all the code in the form's module (Ctrl+A.)
2. Cut to clipboard (Ctrl+X.)
3. Paste back into the empty module (Ctrl+V.)

Does Access set all the event properties for you when you do this? My
recollection is that it does.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

ThomasAJ said:
Thanks but I know all that.

I have many many controls and events. Please tell me that I can do this
automatically somehow or programatically or even magically. Manually would
take a long time and errors would result that would not be picked up for a
long time etc etc. Um does anyone understand the real issues?

--
Regards
Tom


strive4peace" <"strive4peace2006 at yaho said:
Hi Thomas,

go to the code behind your first form -- copy the relevant
event procedures to the code behind your second form. The,
go to each control individually to ensure that the proper
event says [Event Procedure] -- if it does not, choose
[Event Procedure] and click on the builder button (...) to
the right -- if it takes you to just a prcedure declaration
and and End Sub, you still need to copy the code from the
first form.


Whenever you write or paste code, your should ALWAYS compile
it before you attempt to run it.

from the menu: Debug, Compile

fix any errors on the yellow highlighted lines

keep compiling until nothing happens (this is good!)

Warm Regards,
Crystal
Microsoft Access MVP 2006

*
Have an awesome day ;)

remote programming and training
strive4peace2006 at yahoo.com

*

ThomasAJ wrote:
I have a flakey form with many controls and their events.

I have set up a new form and have copied the controls and code to it
and of
course the events have been lost.

Any way of associating the events with the controls easily.
 
Hi Thomas,

If you created another form because there were problems with
the first one, it seems to me that you should test each bit
of code individually -- if it were me, I would move them one
at a time and test each one as I did it.

you might also try decompiling your database

"C:\Program Files\Microsoft Office\Office\MSACCESS.EXE"
"C:\path\filename.mdb" /decompile

if your Access program is located somewhere else, substitute
the correct path

Warm Regards,
Crystal
Microsoft Access MVP 2006

*
Have an awesome day ;)

remote programming and training
strive4peace2006 at yahoo.com

*
 
Thanks Crystal for the tip/s but we are getting away from the issue (I am a
very experienced programmer so no offence but no more tips).

I guess at this stage I really want to know:
1. If ALL code is placed into a new form and THEN ALL controls copied to the
new form will Access associate the correct events. It did associate for me a
few months back for another form whose layout I converted from a very long
form to one with a Tab control. ie I copied whole bunches of controls into
each TAB AFTER I copied ALL the code into the new form.
2. If YES then as my Access is not doing it then maybe it's corrupted ot
maybe my DB is corrupted.
3. If NO then is there a piece of code in cyberspace to perform such a
function, free or otherwise.
 
OMG! You are 100% correct.

Copy and paste the CONTROLS FIRST
THEN the code
ACCESS sets the events correctly.

Thank you very very much.

Now why the heck didn't I try that? Hm... he puts on dunce's hat and slinks
off to corner red-faced.
 
Back
Top