Conditional Formatting

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

Guest

I would really like to be able to change the focus color of a textbox to a different color than white, but I don't believe that it is possible. So what I am trying to do now is change the font color that I have in the active textbox while I am there to some color and then when it has lost focus change it back to the previous color. I am using Access 97, so A2KConditionalFormatting will not work for me
 
Walt,

You could manage a 'focus flag' by changing the background or foreground, or
both, if you wanted.

A reasonably flexible way to do it is sketched out below, 'inventing' a
couple of new properties for the form(s) involved.
Making each form independent is preferable to trying to come up with a
centralised solution ... you don't have to worry about forms opening and
closing ... it all looks after itself (more or less).

Uses nothing that is not supported in A97.


Good luck.
CD

' untested code ...
'================================
' 1. Define variables in General Declarations section of form
Dim curFocus As Control, curFocusBGclr As Long

' 2. Define new properties of form -
ModifiedControl,ControlBGnormal,GotFocusColour
Property Get ModifiedControl() As Control
Set ModifiedControl = curFocus
End Property
Property Set ModifiedControl(ctrl As Control)
Set curFocus = ctrl
End Property
Property Get ControlBGnormal() As Long
ControlBGnormal = curFocusBGclr
End Property
Property Let ControlBGnormal(clr As Long)
curFocusBGclr = clr
End Property
Property Get GotFocusColour() As Long
GotFocusColour = vbRed ' or vbGreen etc ... set this as appropriate
for the form
End Property

' 3. Attach this function call to each OnGotFocus event associated with
the form's controls
' even the controls that do not have a bg color (checkboxes etc)
' ... one way is to enter "=DenoteFocusPoint([Form])" in the Property
sheet
' ... remember Shift/Click will allow you to group several controls,
so that you
' could set the property value for all ctrls involved as a single
entry

' 4. Put the following function in a standard module

Public Function DenoteFocusPoint(Frm As Form)

' called when a control gets the focus
' ... check out the 'last modified' property for the form
' ... if it's now the same control as last time - do nothing
' ... if it's now a different control from last time
' ... set old control back to its previous bg colour
' ... save bg colour of new ctrl, & reset clr to 'gotFocus'
value

Dim oCtrl As Control

Set oCtrl = Frm.ModifiedControl ' first time in, there will be no
control 'that used to have the focus'
If Not (oCtrl Is Nothing) Then
'If oCtrl.Hwnd = Frm.ActiveControl.Hwnd Then Exit Function
If oCtrl.Name = Frm.ActiveControl.Name Then Exit Function
' new focus on form, so reset previous hilite
On Local Error Resume Next ' not every control type will
support a bg color
oCtrl.BackColor = Frm.ControlBGnormal ' but that doesn't matter
End If
Set oCtrl = Frm.ActiveControl
Frm.ModifiedControl = oCtrl
On Local Error Resume Next ' not every control type will support
a bg color
Frm.ControlBGnormal = oCtrl.BackColor
oCtrl.BackColor = Frm.GotFocusColour
Set oCtrl = Nothing
Err.Clear
End Function
'=============================

Walt said:
I would really like to be able to change the focus color of a textbox to a
different color than white, but I don't believe that it is possible. So
what I am trying to do now is change the font color that I have in the
active textbox while I am there to some color and then when it has lost
focus change it back to the previous color. I am using Access 97, so
A2KConditionalFormatting will not work for me.
 
Back
Top