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!

List Box Controlling Colour

Status
Not open for further replies.

matpj

Technical User
Mar 28, 2001
687
GB
I am using a form to record problem tickets, and using a status field (open, pending, in progress and closed)
I need to be able to change the background colour of the form depending on which option is selected from the list; and ideally date-stamp a 'complete date' field and inactivate all other feilds when the status has been set to 'closed'.

I am not too familiar with events and coding and modules etc., so if someone can tell me what to type and where, I would appreciate it!
 
Hello Mat,
This is something I'm sure you can handle!
Place your form in design view and double-click on your list box. This should pop up the "properties dialog" for it. Find the Events tab, then find the "After Update" event. Select in its "field" the choice "Event Procedure". Now notice the little button just to the right "..." . Click this and you'll open up the "Visual Basic" module that is "behind" the form. By pressing this button it will automatically label a "Sub" procedure for you, with a title and an "End Sub". Between the title and the "End Sub", paste in this:

On Error Resume Next
Select Case Me.NameOfYourListBox
Case "Open"
Me.Detail.BackColor = vbGreen
Case "Pending"
Me.Detail.BackColor = vbYellow
Case "In Progress"
Me.Detail.BackColor = vbBlack
Case "Closed"
Me.Detail.BackColor = 16777215
End Select


You have One thing to fix here and that is the name of your list box. What this does is after you make a change (update) to the value in your list, it will check what the value is and react accordingly. Me.Detail is the "body" of your form. VbBlack etc. are Visual Basic "Constants" and this is exactly the same as asking for a color by number (# 0 actually). You replace the constants with numbers as you choose. (Play with the backcolor of your list box and notice on its properties pop up how the "back color" number changes. Record the numbers you want, and put them in to here.)
Yhat's about it. Close, Save and see if it goes! Gord
ghubbell@total.net
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top