Changing text colour OnChange?

G

Guest

Hey is there any way to change the colour of a text box to start off as red text then change to black when the field is updated or entered? I want to open a form with a record for data input with a default date that is red and changes to black when it has been clicked on or changed

Thanks :)
 
K

Kailash Kalyani

The text color is set by the textbox's forecolor property. So if you trigger
the relevant events - afterupdate or onClick to set the forecolor to a
different one, that should do it..

One consideration is that you need to reset it to RED when you're adding a
new record... you can do this by doing this in the onclick event of the add
button or Onload whichever's appropriate for you.

Hope that helps.
--
Kailash Kalyani
MEA Developer Support Center
ITWorx on behalf of Microsoft EMEA GTSC

Katherine said:
Hey is there any way to change the colour of a text box to start off as
red text then change to black when the field is updated or entered? I want
to open a form with a record for data input with a default date that is red
and changes to black when it has been clicked on or changed?
 
D

Damien McBain

Katherine said:
Hey is there any way to change the colour of a text box to start off
as red text then change to black when the field is updated or
entered? I want to open a form with a record for data input with a
default date that is red and changes to black when it has been
clicked on or changed?

Thanks :)

You could use the On Got Focus and On Lost Focus events if you want it to
change to when the cursor is in it and then change back when the cursor is
somewhere else.

Private Sub FieldName_GotFocus()
Me![FieldName].ForeColor = 0 'this is black text
End Sub

Private Sub FieldName_LostFocus()
Me![FieldName].ForeColor = 255 'this is red text
End Sub

If you want it to change after it's been changed then:

Private Sub FieldName_Change()
Me![FieldName].ForeColor = 0 'this is black text
End Sub

If you want it to change when edited and stay changed unless the original
string is re-entered, dim a variable as the data type of the text box and
set its value to the initial value of the text box like

dim initvalue as <whatever>
initvalue = [fieldname]

then you can test for the change in the form's oncurrent event like:

if [fieldname] <> initvalue then
Me![FieldName].ForeColor = 0
else Me![FieldName].ForeColor = 255
end if
 
A

Arvin Meyer

Katherine said:
Hey is there any way to change the colour of a text box to start off as
red text then change to black when the field is updated or entered? I want
to open a form with a record for data input with a default date that is red
and changes to black when it has been clicked on or changed?


The easiest way that I know of is to select all the controls you want to
change color of, in the form's Design View and then go to the Format menu
item and choose Conditional Formatting. In the drop-down list of the
Condition 1 format, choose "Field has focus".

That's it! Your're done.
--
Arvin Meyer, MCP, MVP
Microsoft Access
Free Access downloads:
http://www.datastrat.com
http://www.mvps.org/access
 

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

Top