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

Need to have a rectangle change color based on value

Status
Not open for further replies.

at51178

Technical User
Mar 25, 2002
587
US
Hey guys

I have a form with a dropdown box of 78 pc ids

I also have constructed 78 boxes that represent each pc on the floor.

I have also named each rectangle by it's respective Id

so if I have an ID in my dropdown list that was
"AT123456" then I created a box with the name "AT123456"

what I would like to do is When I choose an ID from the drop down list the corresponding rectangle's back color will change black. I do have some code but it doesn't seem to work.

Dim ctrl As Control
For Each ctrl In Form.Controls
Select Case ctrl.ControlType
Case acRetangle:
If ctrl.Name = Me.cbo_Assertag Then
ctrl.BackColor = vbRed
Else
End If
Case Else
End Select
Next ctrl
 
Hi,

Rectangle is spelt incorrectly and you don't really need the colon after it:

Dim ctrl As Control
For Each ctrl In Form.Controls
Select Case ctrl.ControlType
Case acRectangle
If ctrl.Name = Me!cbo_Assertag Then
ctrl.BackColor = 0 'black
Else
End If
Case Else
End Select
Next ctrl

Bill
 
Hi,

I created test form with 1 Combo Box (cbID)
( RowSource: "AT123456";"AT123457";"AT123458")
and 3 text boxes: AT123456, AT123457, AT123458

This procedure (After Update event) works fine.

Private Sub cbID_AfterUpdate()
On Error Resume Next

Dim ctrl As Control

For Each ctrl In Me.Controls
Select Case ctrl.ControlType
Case acTextBox:
If ctrl.Name = cbID Then
ctrl.BackColor = vbRed
Else
ctrl.BackColor = vbWhite
End If
Case Else
End Select
Next ctrl

End Sub
 
Thanks for answering back guys

I tried both codes and neither of them worked for the rectangle I did try your boriska with the textbox and it worked fine but how do I do it with the rectangle I replaced "acTextbox" with "acRectangle" but nothing happened.
 
I suggest you set a break point in your code, then step through the execution, checking the values of ctrl.Name and cbID to see where it's going wrong.

Ken S.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top