Call Same Function for multiple controls

G

Guest

I have a function that generates a SQL statement based on selections
(checkboxes) the user makes on the form. I want to have that function be
called whenever any of the checkboxes are changed (afterupdate event).

I know that I can create 23 different AfterUpdate event Subs, one for each
check box, and add the line to call the funciton to each sub.

What I don't know is if I can set that function as the AfterUpdate in the
control properties. So I don't have 4-5 lines of code nearly duplicated 23
times.

For example, if I somehow was able to have the function as a macro, I could
select that same macro for all 23 checkboxes without any additional macros or
coding.

Can I select that same function for all 23 checkboxes?
 
M

Marshall Barton

Can said:
I have a function that generates a SQL statement based on selections
(checkboxes) the user makes on the form. I want to have that function be
called whenever any of the checkboxes are changed (afterupdate event).

I know that I can create 23 different AfterUpdate event Subs, one for each
check box, and add the line to call the funciton to each sub.

What I don't know is if I can set that function as the AfterUpdate in the
control properties. So I don't have 4-5 lines of code nearly duplicated 23
times.

For example, if I somehow was able to have the function as a macro, I could
select that same macro for all 23 checkboxes without any additional macros or
coding.

Can I select that same function for all 23 checkboxes?


Yes. Set the AfterUpdate property using this kind of
syntax:

=yourfunction(...)
 
G

Guest

When you have a function

Function YourFunctionName()
' Your code
End Function

In the AfterUpdate event you can write
=YourFunctionName()

Similar to the macro
 
G

Guest

Perfect. Thanks to both of you.

Ofer Cohen said:
When you have a function

Function YourFunctionName()
' Your code
End Function

In the AfterUpdate event you can write
=YourFunctionName()

Similar to the macro
 

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