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!

Problem with a rectangle changing colour, based on a query result!

Status
Not open for further replies.

aarondewberry

IS-IT--Management
Jul 20, 2005
148
0
0
GB
I have a simple table, [table1], with two fields in, [Date] & [Cash].

I also have a form, [frm1], with two text boxes on, [Date1] & [Date2]

I then have a query that SUms the [Cash] field within [Table1], based on the dates entered into the text boxes.

There is a third control, [Value], on [frm1], which shows the output result from my query.

There is an event procedure (After Update) on the [Date2] text box, that updates the [Value] control with the latest query output. See below..

Code:
Private Sub Date2_AfterUpdate()
[Value].Requery
End Sub

I have added a rectangle, [Box1], to [frm1]. And what I want to do, is when the [Value] control is less than 0, I want [Box1] to turn red, else i want it to turn green.

So in the, On Current, Event on the [frm1] properties, I have put the following code...

Code:
Private Sub Form_Current()
Dim green, red As Integer

green = 8454016
red = 255


If [Value] < 0 Then
Me.Box1.BackColor = red
Else
Me.Box1.BackColor = green
End If
End Sub

However, when I trialed this, changing dates that would give me plus and minus values, in the [Value] control. The colour of [Box1] does not change.....
unless I click on the [Value] control, goto design view of the form, then return to normal view. The box then changes colour.

Can anyone help?
 
hmmmmmmmmmmmmmmmmmmmmmmm ... mmmmmmmmmmmmm

Since the procedure whicc could change the .backcolor is (apears to be from the post) only cannel on form current, the procedure ony executes when the even occurs ...

Mayhap a brief review of 'event driven' logic is useful ...



MichaelRed


 
you may like to use vbRed and vbGreen in place of the red and green variables you created. On one line it would be ...

Me.Box1.BackColor = iif([value]<0, vbred, vbgreen)

No need for dims.

Ian Mayor (UK)
Program Error
9 times out of 10 I know what I'm talking about. This must be my tenth reply.
 
Short answer is to call the same colouring code in the Form_Current and the Date2_AfterUpdate event procedures.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top