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!

Changing the ForeColor of a Textbox based on a condition

Status
Not open for further replies.

lookE

IS-IT--Management
Sep 28, 2002
23
0
0
US
Hi everyone,

I'm trying to change the forecolor of a textbox based on the value of another textbox. How can I get the condition to apply to each record and not just the first record? For instance in my code below, if my first record happens to be true, then all the resulting records for Text2 will be red(255) (which is something that I don't want to happen). I'd like the condition to apply to each record. What am I missing? (Please excuse the naming conventions....still new to coding.)

Private Sub Form_Load()

Forms!Form1!Text1.SetFocus
If Me!Text1 = "Alert" Then
Forms!Form1!Text2.SetFocus
Me!Text2.ForeColor = 255
End If

End Sub
 
Hi

You do not say which version of Access you are using, or if the form is a single record view or a continuos form.

If it is a single record form, you need the code in the OnCurrent Event, so that it is execute as you move from record to record.

If it is a continuos form, it depends on the version of Access you have.

Upto and including Access97, it was not standard functionality to allow each 'line' on the form to have different formating, but you may find a work around for this on
From Access 2000 onwards (I think), you have the option of conditional formating on continuos forms, I have not used this, so cannot give detailed instructions.
Hope this helps

Ken Reay
Freelance Solutions Developer
Boldon Information Systems Ltd
UK
kenneth.reaySPAMNOT@talk21.com
remove SPAMNOT to use
 
Ken,

Thank you for posting. I'm using Access97 with continuous forms.

I thought that Conditional Formatting only pertains to the value of that control.
 
Hi

Yes, conditional formating does apply to that control.

The point is in A97, a given control on a continuos form are all instances, so if you change the color (say) of one control, it changes in all instances down the form.

I believe (but I have not used), a method exists in A2K and AXP to overcome this.

If you are using A97 I belive the link I gave you will give you a workarouind and a lot more useful stuff as well

Hope this helps

Ken Reay
Freelance Solutions Developer
Boldon Information Systems Ltd
UK
kenneth.reaySPAMNOT@talk21.com
remove SPAMNOT to use
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top