Leaner Code w/ Multiple Controls Follow Up Question

  • Thread starter Thread starter owp^3
  • Start date Start date
O

owp^3

Doug Steele helped me out a couple of months ago with a way to easily have
all the controls on a form behave the same way using Functions in the
appropriate Event attribute.

So for example, if I want certain controls on a form to change color when
the control has focus then I would write two functions GF() and LF() to
toggle the BackColor property by setting each Control's On Got Focus event
=GF() and On Lost Focus = LF().

This is pretty slick because then I can select all of the controls at once
and set the event properties at once.

So here is my current problem:
We originally did this in a Single Form. Now I'm trying it with a
Continuous Form. The problem is the event handling isn't limited to the
active record. Since I am use Me.ActiveControl.PROPERTY the function applies
the property value to the corresponding control on every record. I want it
to only apply to the control on the active record.

What do I need to change in the following code:
Function GF()
Me.ActiveControl.BackColor = 13434828
If Me.ActiveControl.Controls.Count > 0 Then _
Me.ActiveControl.Controls (0).FontWeight = 700
End Function

Function LF()
Me.ActiveControl.BackColor = vbWhite
If Me.ActiveControl.Controls.Count > 0 Then _
Me.ActiveControl.Controls(0).FontWeight = 400
End Function

Function AU()
Me.ActiveControl.FontBold = True
End Function

Thanks in advance...
owp^3
 
Have you looked at conditional formatting?

It's a little more time consuming if you have a lot of controls on your
form, but you can actually write code that loops through the controls on a
form and sets the conditional formatting for you.

HTH
Dale
 
I can't remember if I considered it at that time or not.

A quick look at the conditional formatting options and the only event/state
available is focus. Which should be fine for two of the three examples in my
original post; but I also have formats triggered by After Update and On Dirty.

So I still need to figure out how to limit application of the function to
the activerecord and not the entire recordset. I will keep it in mind for
other applications, though.

Thanks,
owp^3
 
The only way to do runtime formatting of continuous or datasheet forms is to
use Conditional Formatting. The problem is that although you see multiple
occurances of a control, internally, there is only one, so any formatting
applied programmatically affects all rows.
 
Gotcha!
That's too bad.
OK so I will try conditional formatting for the focus events and leave the
after update events as is applying to all the records.

Not ideal but shouldn't be too noticable a difference to my users.

Thanks for the answer,
owp^3
 
Back
Top