How to get the Control object from an event proc?

  • Thread starter Thread starter Fjordur
  • Start date Start date
F

Fjordur

Hi,
I'm trying to write a single procedure that will be called whenever any of
the fields of a form is modified. The idea is that this proc will check the
coherence of the form any time a field is modified, and maybe suggest
changes.
How can I get the Control object that was modified?

Tried to use the event proc for the "beforeUpdate" of each control to pass
the object to the main control proc but how do I get the control object in
the event proc? Me is not the control but the form object, so Me won't do.

Another way? Preferably if I could skip having an event proc for each field,
all procs making the same call to the main control proc... like calling
directly =mainProc() in each beforeUpdate property of each field, tha'd be
nice.
Thanks for the help
 
If this function is to be called only within the one form. Then all you need
to do is pass the control as an object to the function and the function
should be set up to use the passed value as a control. So you would call it
like this:

SomeVarialbe = CheckThisControl(Me.MyControl)

Then the function would receive it like this:

Function CheckThisControl(AnyCtl As Control) As Boolean

If IsNull(AnyCtl) Then
AntCtl.BackColor = vbRed
CheckThisContol = False
.......
 
Hi,


Screen.ActiveControl should return the active control, but you cannot
"debug step by step" over a statement using that syntax, since the real
active control would have lost the "active" "quality" to the debugger.


Hoping it may help,
Vanderghast, Access MVP
 
Exacly why I suggested the method I did. The ActiveControl property can be
useful, but it can be tricky to handle.

Michel Walsh said:
Hi,


Screen.ActiveControl should return the active control, but you cannot
"debug step by step" over a statement using that syntax, since the real
active control would have lost the "active" "quality" to the debugger.


Hoping it may help,
Vanderghast, Access MVP
 
Back
Top