Get name of a control

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm trying to write some reusable code that will work inside any control
without modification. I want the code to change the font to bold if the
control's value matches certain characteristics.

The thing I can't figure out is how to pull the name of the control without
having to hard code the value. Does someone know the way to refer to a
control without hardcoding it?

If I was refering to a property of the form, I could use the me.property
approach... but how do I reference the properties of an individual control
without having to hard-code the name?

Thanks!

Scott
 
Screen.ActiveControl.

There's also Screen.PreviousControl that you can use if, for example, you've
selected a control and then clicked on a command button.
 
You can loop through a form's controls collection and write code for
the conditions you want.

HTH
 
ScottH--- said:
I'm trying to write some reusable code that will work inside any control
without modification. I want the code to change the font to bold if the
control's value matches certain characteristics.

The thing I can't figure out is how to pull the name of the control without
having to hard code the value. Does someone know the way to refer to a
control without hardcoding it?

If I was refering to a property of the form, I could use the me.property
approach... but how do I reference the properties of an individual control
without having to hard-code the name?


Me.ActiveControl

will reference the control on the form with the focus. The
difference between this a Screen.ActiveControl is that the
active screen object could be something pther than your form
in some (unusual?) situations.
 
Consider using Conditional Formatting for this. Set up the conditional
format on a single control and get it working properly. Then, you can
use the Format Painter tool (PaintBrush) to copy the same rules to the
other controls. If you don't want to copy the regular formatting along
with the C.F., be aware that you can multi-select controls and then
specify common Conditional Formatting.

This will get around your control-name issue because the rules of
conditional formatting are based on the relative "Field Value", not a
hard-coded name.

HTH,

Kevin
 
Back
Top