if function - display in red

Sharon Hague

Registered User.
Local time
Today, 10:33
Joined
Jul 10, 2003
Messages
138
Hi All

I'm not too good with VBA so I would appreciate it if somebody could tell me what I am doing wrong with the following: -

I have a form with a label called Holidays Available. This is worked out from a label called Holiday Entitlement - Holidays Taken.

I want the label Holidays Availble to be displayed in red if this < 0.

Therefore I have entered the following code in the afterupdate properties of this lable as follows: -

Private Sub Holidays_Available_AfterUpdate()

If Me.Holidays_Available < 0 Then
Me.Holidays_Available.FontBold = True
Me.Holidays_Available.ForeColor = vbRed

Else
Me.Holidays_Available.FontBold = False
Me.Holidays_Available.ForeColor = vbBlack
End Sub

When I view this form and there is a - figure displayed it still remains black instead of red.

Can anybody help?

Cheers
 
put the same code in your on current of the form (or call the after update event from the on current, which is even beter)

Regards

The Answering machine

LOL
 
Does it have to be a label and not a locked and diabled textbox?

If you were to use the textbox you could set it's Format property to this: 0[Black];-0[Red]
 
Namliam

Your proceedure causes other problems as I have quite a few if functions in the same form which it seems to interfere with.

Mile-O-Phile

Thanks this has solved my problem.

I always seem to look at the hardest route to my probs and don't think of the easiest. I never thought of entering this in the format property.

Cheers
 
Sharon Hague said:
Namliam

If Me.Holidays_Available < 0 Then
Me.Holidays_Available.FontBold = True
Me.Holidays_Available.ForeColor = vbRed

Else
Me.Holidays_Available.FontBold = False
Me.Holidays_Available.ForeColor = vbBlack
End Sub

When I view this form and there is a - figure displayed it still remains black instead of red.


You have an "If" and "Else" but you need to put "End if" before end sub
Martin
 
Last edited:
namliam said:
put the same code in your on current of the form (or call the after update event from the on current, which is even beter)

Regards

The Answering machine

LOL
Shouldn't it be the other way around, call the current in the after update?;)
 
Rich said:

Shouldn't it be the other way around, call the current in the after update?;)
Not if you have your code allready in the after update event.

But you/she get what i am driving at... Its not advisable / good practice to have the same bit of code all over the place, better to have it in 1 sub somewhere/anywhere and call that sub from all over the place :)

Regards
 

Users who are viewing this thread

Back
Top Bottom