Using a module to control multiple Forms' events

  • Thread starter Thread starter mark_aok
  • Start date Start date
M

mark_aok

Hi all,

I have a navigation bar which exists on nearly all of my forms. It
has buttons to create new items, to search for items, etc.

But to make my navigation bar functional, I need to copy and paste the
EXACT same event code into about 15 forms - incredibly smelly code.
So I was wondering if anyone knows if I can use a module to set a
control's event code. Anyone know if this is possible in Access
2003??

Thanks,
Mark
 
I have a navigation bar which exists on nearly all of my forms. It
has buttons to create new items, to search for items, etc.

But to make my navigation bar functional, I need to copy and paste the
EXACT same event code into about 15 forms - incredibly smelly code.
So I was wondering if anyone knows if I can use a module to set a
control's event code. Anyone know if this is possible in Access
2003??


What's a navigation bar?

If it's a set of command buttons (or other controls) that
you copy/paste onto all those forms, then you can put all
the code in a standard module and make sure each procedure
is a Public Function.

Then you call the appropriate function procedure from the
control's event properties using the syntax =functionname()
instead of [Event Procedure]

If your code is not really **exactly** the same, you will
need to make some changes depending on what the differences
happen to be. Note that you will not be able to use Me in
this arrangement, instead either pass the form object to the
functions with this syntax =functionname(Form) or the
functions can refer to Screen.ActiveForm. Control names
are usually an issue in this kind of scenario, but maybe not
in your situation.
 
I have a navigation bar which exists on nearly all of my forms. It
has buttons to create new items, to search for items, etc.
But to make my navigation bar functional, I need to copy and paste the
EXACT same event code into about 15 forms - incredibly smelly code.
So I was wondering if anyone knows if I can use a module to set a
control's event code. Anyone know if this is possible in Access
2003??

What's a navigation bar?

If it's a set of command buttons (or other controls) that
you copy/paste onto all those forms, then you can put all
the code in a standard module and make sure each procedure
is a Public Function.

Then you call the appropriate function procedure from the
control's event properties using the syntax =functionname()
instead of [Event Procedure]

If your code is not really **exactly** the same, you will
need to make some changes depending on what the differences
happen to be. Note that you will not be able to use Me in
this arrangement, instead either pass the form object to the
functions with this syntax =functionname(Form) or the
functions can refer to Screen.ActiveForm. Control names
are usually an issue in this kind of scenario, but maybe not
in your situation.

Ok thanks, I'll but the code in a module. That really is frustrating
though, how there is no more efficient way of doing this. It's
probably going to take half a day of copy and pasting. Oh well,

Mark
 
I have a navigation bar which exists on nearly all of my forms. It
has buttons to create new items, to search for items, etc.
But to make my navigation bar functional, I need to copy and paste the
EXACT same event code into about 15 forms - incredibly smelly code.
So I was wondering if anyone knows if I can use a module to set a
control's event code. Anyone know if this is possible in Access
2003??

Then you call the appropriate function procedure from the
control's event properties using the syntax =functionname()
instead of [Event Procedure]

Ok thanks, I'll but the code in a module. That really is frustrating
though, how there is no more efficient way of doing this. It's
probably going to take half a day of copy and pasting. Oh well,

Note that if you select multiple controls, you can set the event's property
for all of the selected controls at once through the Properties window.
(doesn't work for multiple forms, unfortunately).

You can also set properties programmatically. For example, if the form's
open, you can set the Click event to run your function using:

Forms!NameOfForm!NameOfButton.OnClick = "=functionname()"

(Note that the equal sign inside the quotes and the parentheses must be
there)
 
I have a navigation bar which exists on nearly all of my forms. It
has buttons to create new items, to search for items, etc.
But to make my navigation bar functional, I need to copy and paste the
EXACT same event code into about 15 forms - incredibly smelly code.
So I was wondering if anyone knows if I can use a module to set a
control's event code. Anyone know if this is possible in Access
2003??

What's a navigation bar?

If it's a set of command buttons (or other controls) that
you copy/paste onto all those forms, then you can put all
the code in a standard module and make sure each procedure
is a Public Function.

Then you call the appropriate function procedure from the
control's event properties using the syntax =functionname()
instead of [Event Procedure]

If your code is not really **exactly** the same, you will
need to make some changes depending on what the differences
happen to be. Note that you will not be able to use Me in
this arrangement, instead either pass the form object to the
functions with this syntax =functionname(Form) or the
functions can refer to Screen.ActiveForm. Control names
are usually an issue in this kind of scenario, but maybe not
in your situation.

Ok thanks, I'll but the code in a module. That really is frustrating
though, how there is no more efficient way of doing this. It's
probably going to take half a day of copy and pasting. Oh well,


What??

Why do you think you need to do all that copying and
pasting? My suggestion only needed **one** copy of the code
in a **standard** module instead of every form's class
module.

You still haven't explained what this "navigation bar" is,
so I don't even know if my suggestion even applies to what
you are trying to do.
 
Back
Top