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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

changing box colors 1

Status
Not open for further replies.

welshone

Programmer
Jul 30, 2001
414
GB
hello,
I have various problems with changing textboxes and normal boxes to different colors, depending on what is in a drop down box.

how can I change the color of a box I have added to my form using if statements ?

eg if status = active then
box.bgcolor = blue
end if

if have tried this way but the color is always black !?


Also how can I change the colors of different lines in a LISTBOX depending on the status field ?

any help would be greatly appreciated.
thanks.
 
You should be using the following to change the backcolor of a box:
Code:
Me.Box.BackColor = 16711680

This long integer value can be created by going to the properties of the box and on the BackColor line click the button to the right with 3-dots ... This will bring up the color palette and after you choose the color that you want and close it the numeric representation of the color will be in the BackColor property.

Post back if you have further questions.

Bob Scriver
Want the best answers? See FAQ181-2886
Nobody believes the official spokesman... but everybody trusts an unidentified source.
Author, Bagdad Bob???

 
thanks alot bob, however how can I get it to change when scrolling through the records ?
I have added the code to oncurrent and onopen, but still no luck !
 
In the OnCurrent event Procedure you must also put the reverse to turn it off.
Code:
If Me![Status] = "Active" then
   Me![Box].Backcolor = 16711680
else
   Me![Box].Backcolor = 16777215
End If

This should turn the box to blue with status is active and back to white when status is not active.

Post back with results.

Bob Scriver
Want the best answers? See FAQ181-2886
Nobody believes the official spokesman... but everybody trusts an unidentified source.
Author, Bagdad Bob???

 
I've put it oncurrent on the form but nothing happens,
problem is my code is :


If STATUS = "entered" Then
CBOX.BackColor = -2147483643 'White
End If

If STATUS = "credited" Then
CBOX.BackColor = 16744576 'blue
End If

If STATUS = "waiting for response" Then
CBOX.BackColor = 4227327 'orange
End If

If STATUS = "rans sheet recieved" Then
CBOX.BackColor = 255 'red
End If

If STATUS = "in transit" Then
CBOX.BackColor = 8454016 'green
End If

If STATUS = "returned, waiting to be checked" Then
CBOX.BackColor = 8454143 'yellow
End If

If STATUS = "to be priced" Then
CBOX.BackColor = 16512 'brown
End If

If STATUS = "to be credited" Then
CBOX.BackColor = 12615935 'pink
End If

 
First of all I would use a Select Case statement instead of all of the IF statements:
Code:
Select Case Me![Status]
    Case "Active"
       Me.Box.Backcolor = 16744576 'Blue
    Case "Entered"
       Me.Box.Backcolor = -2147483643 'White
 . . . .
End Select

I think the box is not changing color back the BackStyle is set to Transparent. Change it to Solid.

This should now work for you.


Bob Scriver
Want the best answers? See FAQ181-2886
Nobody believes the official spokesman... but everybody trusts an unidentified source.
Author, Bagdad Bob???

 
excellent, that all it was, changed it to solid and it is all ok !
thank you v much. !

now can the same sort of thing be done with a list box ?

cheers bob.
 
also bob, do you know how to have more than 3 conditional formatting on a continuous form ?

thanks .
 
welshone: I really don't know if more than three conditions can be set on a particular field. It looks like ACCESS allows you to add up to 3 conditions but no more. Maybe someone else here can chime in a help if they know of better way.

You might try reposting with just that question so that it doesn't get lost buried down in this thread.

Bob Scriver
Want the best answers? See FAQ181-2886
Nobody believes the official spokesman... but everybody trusts an unidentified source.
Author, Bagdad Bob???

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top