BackColor change

K

kirstie adam

Hi All,

I have a field on my form called [Status of Order]

I want it to change color dependant on what it says in it:

Contract Complete = green
Shortfalls Outstanding = red
Contra Charges = red
On Hold = orange

I am using the following code and can't get it to work:

Private Sub Form_Open(Cancel As Integer)
If Me.Status_of_Order = "On Hold" Then
Me.Status_of_Order.BackColor = 33023
ElseIf Me.Status_of_Order = "Contract Complete" Then
Me.Status_of_Order.BackColor = 65280
ElseIf Me.Status_of_Order = "Contra Charges" Then
Me.Status_of_Order.BackColor = 255
ElseIf Me.Status_of_Order = "Shortfalls Outstanding" Then
Me.Status_of_Order.BackColor = 255
Else

End If
End Sub

I can't use conditional formatting as i can only apply 3 rules to it, and i
need 4.

Can someone tell me wht i am doing wrong please?

Thanks,

Kirstie
 
K

Kahuna

kirstie adam said:
I have a field on my form called [Status of Order]

I want it to change color dependant on what it says in it:

Contract Complete = green
Shortfalls Outstanding = red
Contra Charges = red
On Hold = orange

I am using the following code and can't get it to work:

Private Sub Form_Open(Cancel As Integer)
If Me.Status_of_Order = "On Hold" Then
Me.Status_of_Order.BackColor = 33023
ElseIf Me.Status_of_Order = "Contract Complete" Then
Me.Status_of_Order.BackColor = 65280
ElseIf Me.Status_of_Order = "Contra Charges" Then
Me.Status_of_Order.BackColor = 255
ElseIf Me.Status_of_Order = "Shortfalls Outstanding" Then
Me.Status_of_Order.BackColor = 255
Else

End If
End Sub

Assuming your [Status_od_Order] is actually the name of the text field on
the form (not just the underlying record source) this might work for you
Kirstie

If Me!Status_of_Order.Value = "On Hold" Then
Me!Status_of_Order.BackColor = 16777215
Else if Me!Text0.Value = "Contract Complete" then
Me!Text0.BackColor = 255
End If

If you have mistaken the Status_of_Order as a text box name then it'll
probably be called Text0 or similar on your form, and you can either rename
the field in your form or use the Text0 name in your code.

Hope that helps.
 
R

RoyVidar

kirstie adam said:
Hi All,

I have a field on my form called [Status of Order]

I want it to change color dependant on what it says in it:

Contract Complete = green
Shortfalls Outstanding = red
Contra Charges = red
On Hold = orange

I am using the following code and can't get it to work:

Private Sub Form_Open(Cancel As Integer)
If Me.Status_of_Order = "On Hold" Then
Me.Status_of_Order.BackColor = 33023
ElseIf Me.Status_of_Order = "Contract Complete" Then
Me.Status_of_Order.BackColor = 65280
ElseIf Me.Status_of_Order = "Contra Charges" Then
Me.Status_of_Order.BackColor = 255
ElseIf Me.Status_of_Order = "Shortfalls Outstanding" Then
Me.Status_of_Order.BackColor = 255
Else

End If
End Sub

I can't use conditional formatting as i can only apply 3 rules to it,
and i need 4.

Can someone tell me wht i am doing wrong please?

Thanks,

Kirstie

If the name of the control is "Status of Order" - including spaces,
then you need to put the name within brackets

If Me![Status of Order] = ...

Else, could you please elaborate a bit about what the problem is?
What doesn't work, what happens, is there any errormessages - and
if so, which line is highligthed.
 
R

ruralguy via AccessMonster.com

Aside from the other comments in this thread, the Open event is too early in
the process to have values in controls. I actually think you want your code
in the Current event of the form so it will execute for each record viewed.
If you want to execute when the form is opening then use the OnLoad event
which takes place after the controls have a value.

kirstie said:
Hi All,

I have a field on my form called [Status of Order]

I want it to change color dependant on what it says in it:

Contract Complete = green
Shortfalls Outstanding = red
Contra Charges = red
On Hold = orange

I am using the following code and can't get it to work:

Private Sub Form_Open(Cancel As Integer)
If Me.Status_of_Order = "On Hold" Then
Me.Status_of_Order.BackColor = 33023
ElseIf Me.Status_of_Order = "Contract Complete" Then
Me.Status_of_Order.BackColor = 65280
ElseIf Me.Status_of_Order = "Contra Charges" Then
Me.Status_of_Order.BackColor = 255
ElseIf Me.Status_of_Order = "Shortfalls Outstanding" Then
Me.Status_of_Order.BackColor = 255
Else

End If
End Sub

I can't use conditional formatting as i can only apply 3 rules to it, and i
need 4.

Can someone tell me wht i am doing wrong please?

Thanks,

Kirstie
 
K

kirstie adam

Hi All,

I played around with all the suggestions and the following code now works,
the right colours appear at the right time, whereas before the background
was just staying white all the time.

Private Sub Form_Current()
If Me.Status_of_Order = "On Hold" Then
Me.Status_of_Order.BackColor = 33023
ElseIf Me.Status_of_Order = "Contract Complete" Then
Me.Status_of_Order.BackColor = 65280
ElseIf Me.Status_of_Order = "Shortfalls Outstanding" Then
Me.Status_of_Order.BackColor = 255
ElseIf Me.Status_of_Order = "Contra Charges" Then
Me.Status_of_Order.BackColor = 255
Else
Me.Status_of_Order.BackColor = -2147483643
End If
End Sub

Many thanks for your advice all!

Kirstie
ruralguy via AccessMonster.com said:
Aside from the other comments in this thread, the Open event is too early in
the process to have values in controls. I actually think you want your code
in the Current event of the form so it will execute for each record viewed.
If you want to execute when the form is opening then use the OnLoad event
which takes place after the controls have a value.

kirstie said:
Hi All,

I have a field on my form called [Status of Order]

I want it to change color dependant on what it says in it:

Contract Complete = green
Shortfalls Outstanding = red
Contra Charges = red
On Hold = orange

I am using the following code and can't get it to work:

Private Sub Form_Open(Cancel As Integer)
If Me.Status_of_Order = "On Hold" Then
Me.Status_of_Order.BackColor = 33023
ElseIf Me.Status_of_Order = "Contract Complete" Then
Me.Status_of_Order.BackColor = 65280
ElseIf Me.Status_of_Order = "Contra Charges" Then
Me.Status_of_Order.BackColor = 255
ElseIf Me.Status_of_Order = "Shortfalls Outstanding" Then
Me.Status_of_Order.BackColor = 255
Else

End If
End Sub

I can't use conditional formatting as i can only apply 3 rules to it, and i
need 4.

Can someone tell me wht i am doing wrong please?

Thanks,

Kirstie

--
HTH - RuralGuy (RG for short) acXP WinXP Pro
Please post back to this forum so all may benefit.

Message posted via AccessMonster.com
 
R

ruralguy via AccessMonster.com

Thanks for posting back with your success!

kirstie said:
Hi All,

I played around with all the suggestions and the following code now works,
the right colours appear at the right time, whereas before the background
was just staying white all the time.

Private Sub Form_Current()
If Me.Status_of_Order = "On Hold" Then
Me.Status_of_Order.BackColor = 33023
ElseIf Me.Status_of_Order = "Contract Complete" Then
Me.Status_of_Order.BackColor = 65280
ElseIf Me.Status_of_Order = "Shortfalls Outstanding" Then
Me.Status_of_Order.BackColor = 255
ElseIf Me.Status_of_Order = "Contra Charges" Then
Me.Status_of_Order.BackColor = 255
Else
Me.Status_of_Order.BackColor = -2147483643
End If
End Sub

Many thanks for your advice all!

Kirstie
Aside from the other comments in this thread, the Open event is too early in
the process to have values in controls. I actually think you want your code
[quoted text clipped - 37 lines]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top