Adding Event Procedures through Code!

prabha_friend

Prabhakaran Karuppaih
Local time
Today, 22:28
Joined
Mar 22, 2009
Messages
1,034
I am hearing the question you are asking. "Why do I need it?"

I am having more than 100 forms in my application. But the way the form reacts for some errors is mostly the same Thus, no different procedures.

Private Sub Form_Error(DataErr As Integer, Response As Integer)
If DataErr = 3022 Then MsgBox "Duplicate Value"
Response = acDataErrContinue
End Sub

I pasted the above code to all the forms manually previous time(costed me 2 hours). Now they also wants to insert a single code which the undos the last action in it. I am not certain what all changes they are gonna to tell in this error trapping. It's not possible to add this event procedure programmatically to all the forms?
 
Why not make the function public, put it in a module instead of in each forms class module and simply call it from each forms OnError Event. Then if you have to make changes, you only have to make them in one place.
 
To add to a module using VBA take a look at the properties and methods under:
Forms("formname").Module

However 100 forms would suggest either an utterly enormous application or a less than optimum data structure. With a good structure and clever design, one form can often be used in multiple contexts.
 
In this case, I would vote ...
... or a less than optimum data structure.

Absolutely correct. You can hide/unhide controls, disable/enable based on the value of your OpenArgs or tag string sent from the form opening the other form (for example).
With a good structure and clever design, one form can often be used in multiple contexts.
 

Users who are viewing this thread

Back
Top Bottom