Log in

View Full Version : If condition to make result flash or change color the result is less than 8 hrs



ravy
05-31-2007, 04:17 AM
First of I'm new here..I've been dropping by at this Forum from time to time. There are so many helpful tips here..thanks
Here is my challenge. I have database setup to track my employee vacation. On my form, I have a calculating field that would subtract VacAvailable from VacUsed. Ex. ([VacAvailbe]-[VacUsed])= Vleft. My question is, is there code that would make Vleft flash or change color if it is less than 8 hrs? and what would the code be..I'm new in VBA world. Also, can someone recommend me to a good VBA book..?

mattj
05-31-2007, 11:29 AM
You could use contional formatting to change the color - if you wanted it to flash you would need to use code on the form's timer event:


If ([VacAvailbe] - [VacUsed]) < 8 Then
If Me.MyVLeftControl.BackColor = vbRed Then 'or some other color notation
Me.MyVLeftControl.BackColor = vbGreen
ElseIf Me.MyVLeftControl.BackColor = vbGreen Then
Me.MyVLeftControl.BackColor = vbRed
End If
End If

HTH
Matt

Edited 1-Jun-07 by geekgirlau. Reason: insert vba tags

ravy
06-04-2007, 06:01 AM
Hi Matt, thanks for response..Where should I insert this code? Should I insert this code in the Control Source where my formula currently is? Thanks in advince..

mattj
06-04-2007, 08:57 AM
Open the form's properties and select the Events tab. Scroll down and selec the On Timer event. Click the ellipsis (...) to the right of the line, and choose "Code Builder". Place the code between the Private Sub and End Sub lines.
You will need to change the name of the control to match yours, and you will also need to select a value for Timer Interval. So if you wanted the control to flash every second, the timer interval would be 1000 (it's in milliseconds).

HTH
Matt