Drop Down changes background color

J

Jeff

I have a form where I would like to change the background color of the
form based on the selection of a value on a dropdown Combo box
(combobox39). This alerts the user to what program they are dealing
with.

Thanks

Jeff
 
S

Stuart McCall

Jeff said:
I have a form where I would like to change the background color of the
form based on the selection of a value on a dropdown Combo box
(combobox39). This alerts the user to what program they are dealing
with.

Thanks

Jeff

In the AfterUpdate event procedure:

Select Case Me.combobox39
Case 1
Me.BackColor = vbWhite
Case 2
Me.BackColor = vbBlue

'etc. etc.

End Select
 
J

Jeff

Select Case Me.combobox39
Case "Upper"
Me.BackColor = vbYellow
Case "ACE"
Me.BackColor = vbRed
End Select


I'm getting a DEBUG error of:

Method or Data Member not found.

Did I do something wrong?
 
S

Stuart McCall

Jeff said:
Select Case Me.combobox39
Case "Upper"
Me.BackColor = vbYellow
Case "ACE"
Me.BackColor = vbRed
End Select


I'm getting a DEBUG error of:

Method or Data Member not found.

Did I do something wrong?

No. My fault. I'm *always* forgetting this. You must specify the form
section you want to affect. So if all your controls are in the Detail
section:

Select Case Me.combobox39
Case "Upper"
Me.Section(acDetail).BackColor = vbYellow
Case "ACE"
Me.Section(acDetail).BackColor = vbRed
End Select

or (better) :

With Me.Section(acDetail)
Select Case Me.combobox39
Case "Upper"
.BackColor = vbYellow
Case "ACE"
.BackColor = vbRed
End Select
End With
 
J

Jeff

No. My fault. I'm *always* forgetting this. You must specify the form
section you want to affect. So if all your controls are in the Detail
section:

Select Case Me.combobox39
   Case "Upper"
       Me.Section(acDetail).BackColor = vbYellow
   Case "ACE"
       Me.Section(acDetail).BackColor = vbRed
End Select

or (better) :

With Me.Section(acDetail)
    Select Case Me.combobox39
       Case "Upper"
           .BackColor = vbYellow
       Case "ACE"
           .BackColor = vbRed
    End Select
End With

That seemed to work. I also have another screen that I want to do this
to. This combo box has 4 fields in the query and it shows 2 of them in
the dropdown box. I want it to be on the 4th field (which also appears
elsewhere on the form to keep the data there once the form is
refreshed with all the proper data.)

How would that work? I tried using the Combo Box field name (also
Combo Box 39), but it doesn't recognize it. (The field name is
ProgramID).

Thanks!

Jeff
 
S

Stuart McCall

No. My fault. I'm *always* forgetting this. You must specify the form
section you want to affect. So if all your controls are in the Detail
section:

Select Case Me.combobox39
Case "Upper"
Me.Section(acDetail).BackColor = vbYellow
Case "ACE"
Me.Section(acDetail).BackColor = vbRed
End Select

or (better) :

With Me.Section(acDetail)
Select Case Me.combobox39
Case "Upper"
.BackColor = vbYellow
Case "ACE"
.BackColor = vbRed
End Select
End With
That seemed to work. I also have another screen that I want to do this
to. This combo box has 4 fields in the query and it shows 2 of them in
the dropdown box. I want it to be on the 4th field (which also appears
elsewhere on the form to keep the data there once the form is
refreshed with all the proper data.)

How would that work? I tried using the Combo Box field name (also
Combo Box 39), but it doesn't recognize it. (The field name is
ProgramID).

Thanks!

Jeff

You can pull the data from the combo's list via column number, remembering
that the numbers start from zero. So you get the data from the combo like
this:

MsgBox Me.combobox39.Column(3) '3 = fourth column
 

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

Top