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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reset ForeColor to Default?? 2

Status
Not open for further replies.

quest4

Technical User
Aug 27, 2001
735
US
I have a form in which I have a procedure which changes the ForeColor to a different color when a condition is meet. This is part of the code:
If Me![WorkDay1Reason] = "" Then
Me![WorkDay1Reason].ForeColor = vbBlack
Me![WorkDay1].ForeColor = vbBlack
End If
If Me![WorkDay1Reason] = "Bonus" Then
Me![WorkDay1Reason].ForeColor = vbBlue
Me![WorkDay1].ForeColor = vbBlue
End If
The trouble is that the fields change for all of the employees, so I need to know how to reset ForeColor back to its' default when the EmployeeNumber changess. In other words, for this record only.
Also the code pertaining to the "" does not work, if I leave the combo box blank nothing changes, but if I change it to Bonus it changes th ForeColor to blue like it should. I have tried using = Null and IsNull, but it never changes ForeColor to Black like it should. Thank you in advance to anyone helping to corect these two problems.
 
quest,
Which event is this on? On the Form_Current you should set the box to the color depending on the code above, also in after_update (which suggests you should put the color-change code into a sub and call it on current and after_update).

For default you should save the value in a form-scoped variable on load, or if you want to get really fancy, save defaults for all the different colored fields in a table (if you have lots of different default's for different fields), so you never have to change code if a default color change is desired.

When you say you've tried = null or isnull, are you using:
If Isnull( Me![WorkDay1Reason])?

Also note that it you're in Continuous forms, all bets are off, the texbox object color is the same for all records, so a change in one field would make the whole column change.
--Jim
 
Thank you for the response. I am in Single Form and this procedure is running in LostFocus event, I want the changes to take effect when I tab out of the combo box. As far as different ForeColors go, good old 0 or Black will do for the default, much the way it is in a normal form field. I am just trying to make it easy to spot the bad attendance employees, I am using four ForeColors, vb Black, vbBlue, vbGreen, and vbRed. If vbBlack is the same a 0 or Black in the property sheet, then it can be the form default ForeColor for everything in the form, except the titles. As for the IsNull statement goes you got it exactly. I have changed the = "" to = Null and still the same thing no change of color. This is a combo box and "" and Null are not in the drop down list, but LimitToList is not turned on. Basically all I am trying to do is say if the combo box field is empty or blank, change ForeColor to vbBlack. That is the only one that is not working corectly. Maybe a Sub maybe a answer but I am play with 12 different boxes, 6 combo and 6 text boxes and each one has a different name. I am controling the ForeColor of the boxes in pairs, if that really mattersw. Again thank you very much for the response. I have to step out but I will be back at 11:00AM.
 
I made a change, instead ForeColor vbRed in the Else statement I amde ForeColor vbBlack in the Else staement and list out all of the re items instead. The Black now works correctly, when in the Else portion. Go figure. Well the only thing left is the reset ofForeColorwhen a new record comes up and still maintaining the old color on the previous record. Thanks again for your help.
 
Like Jim said, putting your code in the form's On Current event will set the colors right for each record.
 
Thanks for the response. When I make a change to a text box I get sent to the combo box next to it, the ForeColor is changed there depending on what I select in the combo box, and it is for this record only. Do I still move the procedure to the Forms OnCurrent? Do I move all six procedures, one for each combo boxs? Thanks you again for the response.
 
Thanks for the response, but I have to ask this. In both places at the same time? I have never heard of that, but I will try any thing once. Thanks for the help.
 
Dang. It works good. Thanks for the help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top