Changing text colour OnChange?

  • Thread starter Thread starter Guest
  • Start date Start date
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 :)
 
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?
 
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
 
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
 
Back
Top