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

Use a Loop to Change Box Properties 1

Status
Not open for further replies.

Kariera

Programmer
May 27, 2004
9
US
I’m trying to write some VB code in Access that will loop through a recordset. That’s not hard, I have that all set, but one of the fields of the recordset is “code”. On the form I’m using there is a corresponding square for each “code” value. What I want to do is use the value of “code” to find the box on the form and change its backcolor. I can’t figure out how to take the “code” value and make an object whose properties can be set. I tried stringing it together, but it won’t work. Any ideas? THANK YOU!!!

Set db = CurrentDb()

sqlRS_Auto = "SELECT tblNewspaperData.Code, tblNewspaperData.Automotive FROM tblNewspaperData;"

Set RS = db.openrecordset(sqlRS_Auto)


If RS.EOF Then
Set db = Nothing
Set RS = Nothing
Exit Sub
Else
Do While Not RS.EOF
valCode = RS("Code")
valAuto = RS("Automotive")
valBoxText = "Me.box" & valCode

If valAuto > 0 And valAuto < 10 Then

valBox.BackColor = 10040115 ‘ <= This doesn’t work!!!!

Else
End If
RS.MoveNext

Loop

End If

 
Try the syntax:

[tt]Me("Box" & valAuto).BackColor[/tt]

Roy-Vidar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top