A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

"Field has focus" condidional formatting - Not working



 
 
Thread Tools Display Modes
  #1  
Old February 17th, 2009, 05:49 PM posted to microsoft.public.access.forms
Silvio
external usenet poster
 
Posts: 140
Default "Field has focus" condidional formatting - Not working

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

  #2  
Old February 18th, 2009, 03:50 AM posted to microsoft.public.access.forms
Allen Browne
external usenet poster
 
Posts: 11,706
Default "Field has focus" condidional formatting - Not working

"Silvio" wrote in message
...
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

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

  #3  
Old February 18th, 2009, 01:44 PM posted to microsoft.public.access.forms
Silvio
external usenet poster
 
Posts: 140
Default "Field has focus" condidional formatting - Not working

Thank you again Alllen, this works just fine!

"Allen Browne" wrote:

"Silvio" wrote in message
...
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

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.


 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 04:33 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.