"Field has focus" condidional formatting - Not working

S

Silvio

Hello, I have several sub forms with fields turning green when the field has
the focus (user click in it). However, I have a couple sub forms that refuse
to cooperate, when I click in it nothing happens, the field remains white.
The conditional formatting is enforced via the standard "Conditional
Formatting" menu in MS Access 2003 with SP2. Does anyone know how to solve
this mystery?

Thanks,
Silvio
 
A

Allen Browne

Silvio said:
Hello, I have several sub forms with fields turning green when the field
has
the focus (user click in it). However, I have a couple sub forms that
refuse
to cooperate, when I click in it nothing happens, the field remains white.
The conditional formatting is enforced via the standard "Conditional
Formatting" menu in MS Access 2003 with SP2. Does anyone know how
to solve this mystery?

Silvio, this might be easier than setting up conditional formatting for all
the controls.

1. Copy the code below into a standard module, and save with a name such as
Module1.

2. For any form where you want to do this, set its OnLoad property to:
=SetupHighlight([Form])

It programmatically sets up each control so it goes yellow when it gets
focus, and goes back to white when it loses focus. It only works for text
boxes and combos where the BackStyle is normal (not transparent), and
GotFocus/LostFocus is not already in use.

Public Function SetupHighlight(frm As Form)
Dim ctl As Access.Control

For Each ctl In frm.Controls
Select Case ctl.ControlType
Case acTextBox, acComboBox
If ctl.BackStyle = 1 Then
If (ctl.OnGotFocus = vbNullString) And _
(ctl.OnLostFocus = vbNullString) Then
ctl.OnGotFocus = "=Hilight([" & ctl.Name & "], True)"
ctl.OnLostFocus = "=Hilight([" & ctl.Name & "], False)"
End If
End If
End Select
Next
End Function
Public Function Hilight(ctl As Control, bOn As Boolean)
Const lngcHilightOn = vbYellow
Const lngcHilightOff = vbWhite

If bOn Then
ctl.BackColor = lngcHilightOn
Else
ctl.BackColor = lngcHilightOff
End If
End Function
 
S

Silvio

Thank you again Alllen, this works just fine!

Allen Browne said:
Silvio said:
Hello, I have several sub forms with fields turning green when the field
has
the focus (user click in it). However, I have a couple sub forms that
refuse
to cooperate, when I click in it nothing happens, the field remains white.
The conditional formatting is enforced via the standard "Conditional
Formatting" menu in MS Access 2003 with SP2. Does anyone know how
to solve this mystery?

Silvio, this might be easier than setting up conditional formatting for all
the controls.

1. Copy the code below into a standard module, and save with a name such as
Module1.

2. For any form where you want to do this, set its OnLoad property to:
=SetupHighlight([Form])

It programmatically sets up each control so it goes yellow when it gets
focus, and goes back to white when it loses focus. It only works for text
boxes and combos where the BackStyle is normal (not transparent), and
GotFocus/LostFocus is not already in use.

Public Function SetupHighlight(frm As Form)
Dim ctl As Access.Control

For Each ctl In frm.Controls
Select Case ctl.ControlType
Case acTextBox, acComboBox
If ctl.BackStyle = 1 Then
If (ctl.OnGotFocus = vbNullString) And _
(ctl.OnLostFocus = vbNullString) Then
ctl.OnGotFocus = "=Hilight([" & ctl.Name & "], True)"
ctl.OnLostFocus = "=Hilight([" & ctl.Name & "], False)"
End If
End If
End Select
Next
End Function
Public Function Hilight(ctl As Control, bOn As Boolean)
Const lngcHilightOn = vbYellow
Const lngcHilightOff = vbWhite

If bOn Then
ctl.BackColor = lngcHilightOn
Else
ctl.BackColor = lngcHilightOff
End If
End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top