Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Label change color after field update?

Status
Not open for further replies.

cheyenne2002

Instructor
Jul 26, 2005
229
0
0
US
I'm not even sure if this is possible and if so I'm not sure I would have the smarts to accomplish it, but here goes.

Now the boss wants to know if we can fix it so that certain fields (actually the labels) will show up in red until there is data entered into the actual field.

Any know if it is possible? If so, is it easy?

Sam
 
I do this ...
In the OnCurrent event of the form and in the AfterUpdate event of the textbox, put

Me![Label].BackColor = IIf(IsNull(Me![textbox]), 255, 16777215)

Bob

 
If I enter this in teh OnCurrent event of the form I need to enter the label name, right?

If that is so, can this only work for one field on a form.

I'm going to go try it, but wanted to check this out.

Thank you.
Sam
 
AS long as the labels are associated with the controls you can loop through the controls collection and check them all with a public sub.

In the example, I used 'chkMe' as the tag value for the labels I wanted to have checked.
Code:
Public Sub checkVals()
For Each ctl In Me.Controls
If ctl.ControlType = acLabel And ctl.Tag = "chkMe" Then
If nz(ctl.Parent, "") = "" Then
ctl.ForeColor = vbRed
Else
ctl.ForeColor = vbBlack
End If
End If
Next ctl
End Sub

Then you'd run checkVals on the afterupdate events of the textboxes.

HTH


John

Use what you have,
Learn what you can,
Create what you need.
 
right ... label name and textbox name

If you have only 2 or 3 labels, write a line for each; if many, you could use TAG property and write a little SUB to change all those with a given TAG

Bob
 
How are ya cheyenne2002 . . .

If you have access 2k or higher, [blue]Conditional Formatting[/blue] would work great here! The expression would be:
Code:
[blue][purple]For numeric textbox:[/purple]
   IsNull([TextboxName])

[purple]For string textbox[/purple]
   [TextboxName] = ""[/blue]
If you use conditional formatting, don't forget to disable other interacting code that controls the color.

Calvin.gif
See Ya! . . . . . .
 
Hi AceMan1,

I am using Access 2000. I forgot about conditional formatting.

I'll check that.
Sam

PS: everytime I think I have this almost done, he (the boss) wants more. But he keeps saying "Are you almost done?" Lost several days due to hurricane preps this past week......
 
AceMan1,
I don't think conditional formatting will work. I can not do conditional formatting on the label based on what is in the field.

Sam

I will look at the other great suggestions.
 
cheyenne2002 . . .

. . . so make the labels textboxes instead! (easily morphed).

Calvin.gif
See Ya! . . . . . .
 
Sam, did you try the checkVals sub? It worked a treat for me.

John

Use what you have,
Learn what you can,
Create what you need.
 
AceMan1:

Duh! Where is my brain......definately not where it should be. I must need a vacation. If I could find a place that wasn't having hurricanes, earthquakes or tidal waves I might consider it.

John:

I have not yet, but will look into it as soon as I finish my keyword search, which I think I have got fixed.

Thanks again guys you are the best.
Sam
 
cheyenne2002 . . .

[blue]Right-cick[/blue] any label, select [blue]Change To[/blue] . . .

Calvin.gif
See Ya! . . . . . .
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top