I have a form with 100 textboxes on & I want to loop through table records & colour the textboxes which meet the criteria. The textboxes are named 'txt1' , 'txt2' & so on to 100. The code below works to a degree but not correctly, when I use the code it changes the colour of the first textbox which meets the criteria but then when it loops it re-colours the first matching textbox & ends up just colouring the textbox which meets the criteria of the last recordset.
Private Sub DisplayStaff()
Dim rst As DAO.Recordset2
Dim strSQL As String
Dim i As Integer
Dim intYear As Integer
SetCalendar
strSQL = "SELECT * FROM [tblYearStaffTemp] WHERE [UserName] =’Simon Jones';"
Set rst = CurrentDb.OpenRecordset(strSQL)
If rst.RecordCount > 0 Then
rst.MoveFirst
Do While Not rst.EOF
For i = 1 To 100
If rst!DV = i And rst!yr = intYear Then
Me("Txt" & i).BackColor = vbBlack
Else
Me("Txt " & i).BackColor = vbWhite
End If
Next i
rst.MoveNext
Loop
rst.Close
Set rst = Nothing
Else
rst.Close
Set rst = Nothing
End If
End Sub
Any assistance would be appreciated.
Freddy
Private Sub DisplayStaff()
Dim rst As DAO.Recordset2
Dim strSQL As String
Dim i As Integer
Dim intYear As Integer
SetCalendar
strSQL = "SELECT * FROM [tblYearStaffTemp] WHERE [UserName] =’Simon Jones';"
Set rst = CurrentDb.OpenRecordset(strSQL)
If rst.RecordCount > 0 Then
rst.MoveFirst
Do While Not rst.EOF
For i = 1 To 100
If rst!DV = i And rst!yr = intYear Then
Me("Txt" & i).BackColor = vbBlack
Else
Me("Txt " & i).BackColor = vbWhite
End If
Next i
rst.MoveNext
Loop
rst.Close
Set rst = Nothing
Else
rst.Close
Set rst = Nothing
End If
End Sub
Any assistance would be appreciated.
Freddy