Conditional Formatting

  • Thread starter Thread starter Bill Sturdevant
  • Start date Start date
B

Bill Sturdevant

In a conditional formatting expression, is there a way to
reference the name of the field you are in without
specifically naming the field?

For example, I would like to do this:

Iif(myFunction(me.field.name) = 7,true,false)

Then, myFunction would use the name of the field to do
some logic and return either true of false.

This would allow me to put a "generic" condition
expression in a bunch (156) of fields without having to
make each one unique.
 
Essentially, no.

Screen.ActiveControl is not the same thing as the field that the conditional
formatting belongs to.

It is possible to programmatically assign a property to each text/combo box
on a form, which includes the name of the control assigned to. This example
assigns a function to the OnGotFocus and OnLostFocus properties of the form,
so that the active control is highlighed:
Public Function MakeHighlight(strFormName As String) As Boolean
Dim ctl As Control
DoCmd.OpenForm strFormName, acDesign
For Each ctl In Forms(strFormName).Controls
If ctl.ControlType = acTextBox Or ctl.ControlType = acComboBox Then
ctl.OnGotFocus = "=Highlight([" & ctl.Name & "],True)"
ctl.OnLostFocus = "=Highlight([" & ctl.Name & "],False)"
End If
Next
Set ctl = Nothing
End Function
Public Function Highlight(ctl As Control, bShow As Boolean)
ctl.BackColor = IIf(bShow, vbYellow, vbWhite)
End Function

You are probably tired of us saying that 156 fields represents a
non-normalized design.
 
Allen,

I am too far down this path to change my approach but I am
intrigued by alternatives you might suggest.

For each project ,and within project for each person
assigned, I have to display a screen with 3 years of
fiscal weeks in a format that sort of looks like a
calendar (156 controls), so the user can enter percentage
of utilization of that person on that project. Below that
I have to display the same thing showing which weeks have
over-utilization because this person has been assigned to
too much work (on this project and all others) during a
given week (156 additional controls).

Bill
-----Original Message-----
Essentially, no.

Screen.ActiveControl is not the same thing as the field that the conditional
formatting belongs to.

It is possible to programmatically assign a property to each text/combo box
on a form, which includes the name of the control assigned to. This example
assigns a function to the OnGotFocus and OnLostFocus properties of the form,
so that the active control is highlighed:
Public Function MakeHighlight(strFormName As String) As Boolean
Dim ctl As Control
DoCmd.OpenForm strFormName, acDesign
For Each ctl In Forms(strFormName).Controls
If ctl.ControlType = acTextBox Or ctl.ControlType = acComboBox Then
ctl.OnGotFocus = "=Highlight([" & ctl.Name & "],True)"
ctl.OnLostFocus = "=Highlight([" & ctl.Name & "],False)"
End If
Next
Set ctl = Nothing
End Function
Public Function Highlight(ctl As Control, bShow As Boolean)
ctl.BackColor = IIf(bShow, vbYellow, vbWhite)
End Function

You are probably tired of us saying that 156 fields represents a
non-normalized design.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

In a conditional formatting expression, is there a way to
reference the name of the field you are in without
specifically naming the field?

For example, I would like to do this:

Iif(myFunction(me.field.name) = 7,true,false)

Then, myFunction would use the name of the field to do
some logic and return either true of false.

This would allow me to put a "generic" condition
expression in a bunch (156) of fields without having to
make each one unique.


.
 
You can use Conditional Formatting to achive the desired results.
Further you can do it programmatically wihtout having to add any code to
each control individually.
Look at the "CustomerIncCOntinuousViewCurrentRow sample form here:
http://www.lebans.com/conditionalformatting.htm

--

HTH
Stephen Lebans
http://www.lebans.com
Access Code, Tips and Tricks
Please respond only to the newsgroups so everyone can benefit.


Bill Sturdevant said:
Allen,

I am too far down this path to change my approach but I am
intrigued by alternatives you might suggest.

For each project ,and within project for each person
assigned, I have to display a screen with 3 years of
fiscal weeks in a format that sort of looks like a
calendar (156 controls), so the user can enter percentage
of utilization of that person on that project. Below that
I have to display the same thing showing which weeks have
over-utilization because this person has been assigned to
too much work (on this project and all others) during a
given week (156 additional controls).

Bill
-----Original Message-----
Essentially, no.

Screen.ActiveControl is not the same thing as the field that the conditional
formatting belongs to.

It is possible to programmatically assign a property to each text/combo box
on a form, which includes the name of the control assigned to. This example
assigns a function to the OnGotFocus and OnLostFocus properties of the form,
so that the active control is highlighed:
Public Function MakeHighlight(strFormName As String) As Boolean
Dim ctl As Control
DoCmd.OpenForm strFormName, acDesign
For Each ctl In Forms(strFormName).Controls
If ctl.ControlType = acTextBox Or ctl.ControlType = acComboBox Then
ctl.OnGotFocus = "=Highlight([" & ctl.Name & "],True)"
ctl.OnLostFocus = "=Highlight([" & ctl.Name & "],False)"
End If
Next
Set ctl = Nothing
End Function
Public Function Highlight(ctl As Control, bShow As Boolean)
ctl.BackColor = IIf(bShow, vbYellow, vbWhite)
End Function

You are probably tired of us saying that 156 fields represents a
non-normalized design.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

In a conditional formatting expression, is there a way to
reference the name of the field you are in without
specifically naming the field?

For example, I would like to do this:

Iif(myFunction(me.field.name) = 7,true,false)

Then, myFunction would use the name of the field to do
some logic and return either true of false.

This would allow me to put a "generic" condition
expression in a bunch (156) of fields without having to
make each one unique.


.
 
Back
Top