Hi,
Please can I have some VBA advice. I am writing some code so the Order_Status field back color changes depending on what text the field contains. This is what I have done so far:
I am new to writing code and can't figure out what syntax to use for this. I am currently doing something similar to a formula by saying If Order_Status = "text" Then. It seems that this simple approach isn't working with VBA and I'm sure it's a bit more complex than that!
How can I get this to work?
Thanks very much,
Chris
Please can I have some VBA advice. I am writing some code so the Order_Status field back color changes depending on what text the field contains. This is what I have done so far:
Code:
Private Sub Form_Current()
Dim lngOrange As Long, lngPink As Long, lngYellow As Long, lngGreen As Long
Dim lngGrey As Long, lngRed As Long, lngPurple As Long, lngBeige As Long
lngOrange = RGB(255, 192, 0)
lngPink = RGB(255, 153, 204)
lngYellow = RGB(255, 255, 0)
lngGreen = RGB(155, 187, 89)
lngGrey = RGB(89, 89, 89)
lngRed = RGB(255, 0, 0)
lngPurple = RGB(128, 100, 162)
lngBeige = RGB(148, 138, 84)
lngWhite = RGB(255, 255, 255)
If Me!Order_Status.Value = "Direct Delivery - Awaiting Invoicing" Then
Me!Order_Status.BackColor = lngOrange
End If
If Me!Order_Status.Value = "Delayed - Delivery Date TBA" Then
Me!Order_Status.BackColor = lngPink
End If
If Me!Order_Status.Value = "Awaiting Planning" Then
Me!Order_Status.BackColor = lngYellow
End If
If Me!Order_Status.Value = "On Schedule" Then
Me!Order_Status.BackColor = lngGreen
End If
If Me!Order_Status.Value = "On hold" Then
Me!Order_Status.BackColor = lngGrey
End If
If Me!Order_Status.Value = "Cancelled" Then
Me!Order_Status.BackColor = lngRed
End If
If Me!Order_Status.Value = "Order Complete" Then
Me!Order_Status.BackColor = lngPurple
End If
If Me!Order_Status.Value = "Awaiting Collection" Then
Me!Order_Status.BackColor = lngBeige
Else
Me!Order_Status.BackColor = lngWhite
End If
End Sub
I am new to writing code and can't figure out what syntax to use for this. I am currently doing something similar to a formula by saying If Order_Status = "text" Then. It seems that this simple approach isn't working with VBA and I'm sure it's a bit more complex than that!
How can I get this to work?
Thanks very much,
Chris