A hairbrained idea

G

Guest

This is a bit of a leap but worth asking anyway. I have a form with around
42 subforms. Think of it as a calendar although it is a bit more
sophisticated than that. Each subform has a different datasource and name
but the code is the same in each subform. I have a few subs including
keypress to manage where the cursor moves to, after update to validate input,
and a sub to set certain field names for the key press - which is the next
and previous subform.

I expect the code will change at some point and am trying to avoid updating
code in 42 forms. Is there a way to import code into the subform using vba?
If I could store it in a module, and import it at runtime, I can save a lot
of cutting and pasting.

Basically I want a command that says go and copy all the code in this module
and paste it into this form. One other complication. The program will be an
mde file when I finish.
 
M

Marshall Barton

NevilleT said:
This is a bit of a leap but worth asking anyway. I have a form with around
42 subforms. Think of it as a calendar although it is a bit more
sophisticated than that. Each subform has a different datasource and name
but the code is the same in each subform. I have a few subs including
keypress to manage where the cursor moves to, after update to validate input,
and a sub to set certain field names for the key press - which is the next
and previous subform.

I expect the code will change at some point and am trying to avoid updating
code in 42 forms. Is there a way to import code into the subform using vba?
If I could store it in a module, and import it at runtime, I can save a lot
of cutting and pasting.

Basically I want a command that says go and copy all the code in this module
and paste it into this form. One other complication. The program will be an
mde file when I finish.


You right, that arrangement seems unworkable.

I suspect that there is a way for you to use a single form
object in all 42 subform controls. The subform's event
procedures can determine which subform control is has the
focus by using
Parent.ActiveControl.Name
So, if you name the subform controls in a regular way it
shouldn't be to difficult to have the code deal with it.

The Open and Load events might be tricky to deal with so you
should probably manage tohse activities from the main form
after leavin the subform object's RecordSource property
empty.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top