Label/Text box colours

S

Stub932

How can I make a field (bound or unbound) box in a form, produce a colour
background when the user types in say a date then exits the field box?
Basically having a colour background to visually show a populated field.
 
A

Arvin Meyer

Stub932 said:
How can I make a field (bound or unbound) box in a form, produce a colour
background when the user types in say a date then exits the field box?
Basically having a colour background to visually show a populated field.

You can use Conditional Formatting. While in Design View, click on the
textbox and then go to the Format menu and choose Conditional Formatting.
The wizard is self explanitory.
--
Arvin Meyer, MCP, MVP
Microsoft Access
Free Access downloads:
http://www.datastrat.com
http://www.mvps.org/access
 
B

Brendan Reynolds

Add the following to both the Current event procedure of the form, and the
AfterUpdate event procedure of the text box ...

If Len(Trim$(Me!NameOfTextbox & vbNullString)) = 0 Then
'no data
Me!NameOfTextBox.BackColor = vbWhite
Else
'data
Me!Text0.BackColor = vbYellow
End If

In this example I've used the VB colour constants, vbWhite and vbYellow.
There are only a few of these, for a wider range of colours check out the
RGB function.
 
S

Stub932

Thanks, its working nicely.
Can i just ask if the text colour can be changed at the same time as the
background colour when the field is populated ?
 
D

Douglas J. Steele

Sure. The sample shows changing BackColor. The text colour is the ForeColor
property.
 

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

Similar Threads


Top