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

Change background color text font if date goes past today 6

Status
Not open for further replies.

Sugada

IS-IT--Management
Aug 1, 2001
33
US
Hi all, I'm new to this whole thing and would like some help.

I want to be able to make aware of a date that is now past on my form. The field name is Warrentee date. That if the date in this field goes beyond today, then change the font color or background color, or even flash the text in that field.

Has anyone done this before? Sugada
 
Done all the time. Very simply.

Steve King

Sub Warrantee_AfterUpdate
ChangeColor
End If
Sub Form_Current
ChangeColor
End If

Sub Private ChangeColor()

If Me.Warrentee < Date Then
Me.Warrantee.BackColor = CONSTANTFORCOLORWHITE
Me.Warrantee.FrontColor = CONSTANTFORCOLORBLACK
Else
Me.Warrantee.BackColor = CONSTANTFORCOLORRED
Me.Warrantee.FrontColor = CONSTANTFORCOLORWHITE
End If

End Sub Growth follows a healthy professional curiosity
 
I copied and pasted this into my code and it changes the 'Sub Private ChangeColor()&quot; to red.

What did I do wrong? Assume something probably. That always gets me in trouble. Thanks for your help so far.

It makes sense but I just don't know the code well enough to take what you said and run with it. Sorry. Sugada
 
it is Private Sub ChangeColor(),

not Sub Private ChangeColor().

ruth.jonkman@wcom.com
 
and it's not 'front color', it's forecolor.

Private Sub ChangeColor()

If Me.Warrentee < Date Then
Me.Warrentee.BackColor = vbWhite
Me.Warrentee.ForeColor = vbBlack
Else
Me.Warrentee.BackColor = vbRed
Me.Warrentee.ForeColor = vbWhite
End If

End Sub ruth.jonkman@wcom.com
 
I just tested this. It works. Text0 is a text box

Private Sub Text0_Exit(Cancel As Integer)
Call ChangeColor
End Sub

Private Sub ChangeColor()
Dim MyDate As Date
MyDate = Me.Text0
If MyDate > Now() Then
Me.text0.backcolor = 255 'changes text box text0
Me.Detail.BackColor = 255 'Changes whole form
Else
Me.Detail.BackColor = 8421504
End If
End Sub
Tyrone Lumley
augerinn@gte.net
 
Thanks everyone for your help. I'm having no errors when running what I put in, but it just doesn't work. I have change the data in the text box and it didn't update it or seem to run the code. I don't know why.

Let me ask you this. What is wrong with this code and why doesn't this way work? I'm I thinking way off line here?
___________________________________________
Private Sub Warranty_AfterUpdate()
If Warranty > Now() Then
Warranty.BackColor = 255
Else
Warranty.BackColor = 16777215
End If
End Sub
____________________________________________

Here is what I have that does work on a text box with no data. I simply want the same thing if the data is over todays date.
____________________________________________
Private Sub VideoCard_AfterUpdate()
If IsNull(VideoCard.Value) Then
VideoCard.BackColor = 255
Else
VideoCard.BackColor = 16777215
End If
End Sub
____________________________________________
Sugada!
JSeymour@acloche.com
 
What form view are you using? Datasheet, continuous, or single form?

The above suggestions only work for single forms. If you want to change a text box, per record,for a continous form, you will need a bit more trickery.

ljprodev@yahoo.com
ProDev, MS Access Applications B-)
 
I got it to work. LOL

Now, how can I get it to update or run the code when the record first comes up? I had to accually change the date in order for it to work. For entering new records this is great, but what about the data already there?

Should the event procedure be on &quot;before update&quot;?

I love it when things come together. Sugada Everyone!
 
do you also have the code:

Sub Form_Current
ChangeColor
End Sub

i thought your field name was Warrentee. but in your code you wrote warranty. try using Me. before the field name. (me.warranty). that way you will see if you typed the name correctly because Access will help fill it in for you.

Something i have found helpful is to temporarily put the code:
msgbox &quot;hi&quot; in my code before the IF statement. that way i see if the code is working at all.
ruth.jonkman@wcom.com
 
That code will only work after you update the Warranty text box. It will then stay that color until you again change a value in the Warranty text box. You MUST include it also in the Form Current event which will evaluate it every time you change to a different record.

Steve King Growth follows a healthy professional curiosity
 
That did it.

I added to the Form Current event

Call Warranty_AfterUpdate

And that did the trick. Cool. Thanks you everyone. :-D

I was in school today.

Sugada!
 
how about the second part of the original question: &quot;...or even flash the text in that field.&quot;


Any ideas on how to blink text? would it be something with the timer event? ruth.jonkman@wcom.com
 
Flash would be in the timer, could set timer to 250 and modify code like this and place it in the Timer event:

If Warranty > Date() Then
Warranty.BackColor = vbRed
If Warranty.ForeColor = vbRed
Warranty.ForeColor = vbWhite
Else
Warranty.ForeColor = vbRed
End If
Else
Warranty.BackColor = vbWhite
Warranty.ForeColor = vbBlack
End If

Now you'll have a Red background that will blink white text when the Warranty is greater than the system date. And when it's less than or equal to the system date the box will be White background with black text. If you want to use this you can get rid of all the other code in the other events and just use this in the timer event.

HTH
Joe Miller
joe.miller@flotech.net
 
Joe,
the flashing works perfectly!

thanks.

does it take a lot of memory though? ruth.jonkman@wcom.com
 
Not memory, but it does use some system resources because it fires a lot. You can change it to check every second instead of every quarter second by using 1000 in the Timer Value.

Joe Miller
joe.miller@flotech.net
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top