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
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