S
sjg1314
I have a small database, but it has 11 Forms and and even more subforms
and special purpose forms. I'm an expert programmer but an MS Access
2000 Visual Basic beginner. As I learn more about the language, I find
myself going back and making similar changes to many of the Forms.
Often I have to put little bits of code in multiple places--besides
being monotonous, the chances of slipping up somewhere is pretty high.
So I'd like to centralize code as much as possible so that there is one
place I can go to make changes to all Forms or all Forms of a certain
type. In order to use some of the techniques I know, I have to
programmatically set up event handlers.
For instance, to set a resize handler for all Forms, I could create a
subroutine that gets called whenever a Form is opened or loaded. This
method would set a Form's OnResize property to "=handleResize()".
Great!
Now I want to do the same for an error handler. The problem is that the
Error event has two parameters, DataErr and Response, and its not
useful without them. Is there any way to programmatically set up the
event handler to call something like "=handleError(DataErr, Response)".
Now, I know I can set up an OnError handler that then calls my
subroutine. This requires that I go into the Form, set the OnError
property to "[Event Procedure]" and then type some code that transfers
the work my special method. This is better than nothing, but not much
better, because I don't just want to do this for Forms, I want to set
up handlers for Controls in a Form.
For example, I may want a Focus handler for all text and combo box
fields in a form. With code, I can cycle through all the Controls in
the Form and set up the handlers (which actually works for Focus events
because they don't have any arguments). Without program automation, I
have to go to each control and set up the GotFocus and LostFocus
handlers for each of them. If I create a new text or combo box field, I
have to remember to set up the handlers.
I suspect that this is hole in VBA 2000 that I'll just have to live
with, but I'm hoping to get either an authoritative "can't be done" or
"here's how to do this" or even "here's an alternate way to solve the
problem".
Thanks!
and special purpose forms. I'm an expert programmer but an MS Access
2000 Visual Basic beginner. As I learn more about the language, I find
myself going back and making similar changes to many of the Forms.
Often I have to put little bits of code in multiple places--besides
being monotonous, the chances of slipping up somewhere is pretty high.
So I'd like to centralize code as much as possible so that there is one
place I can go to make changes to all Forms or all Forms of a certain
type. In order to use some of the techniques I know, I have to
programmatically set up event handlers.
For instance, to set a resize handler for all Forms, I could create a
subroutine that gets called whenever a Form is opened or loaded. This
method would set a Form's OnResize property to "=handleResize()".
Great!
Now I want to do the same for an error handler. The problem is that the
Error event has two parameters, DataErr and Response, and its not
useful without them. Is there any way to programmatically set up the
event handler to call something like "=handleError(DataErr, Response)".
Now, I know I can set up an OnError handler that then calls my
subroutine. This requires that I go into the Form, set the OnError
property to "[Event Procedure]" and then type some code that transfers
the work my special method. This is better than nothing, but not much
better, because I don't just want to do this for Forms, I want to set
up handlers for Controls in a Form.
For example, I may want a Focus handler for all text and combo box
fields in a form. With code, I can cycle through all the Controls in
the Form and set up the handlers (which actually works for Focus events
because they don't have any arguments). Without program automation, I
have to go to each control and set up the GotFocus and LostFocus
handlers for each of them. If I create a new text or combo box field, I
have to remember to set up the handlers.
I suspect that this is hole in VBA 2000 that I'll just have to live
with, but I'm hoping to get either an authoritative "can't be done" or
"here's how to do this" or even "here's an alternate way to solve the
problem".
Thanks!