我以连续的形式突出显示字段,字段名称来自FieldModified
字段。该代码确实遍历了所有记录行,但突出显示了其他字段以及FieldModified
字段。我确保所有字段名称都与FieldModified
文本框名称匹配。但是我不明白为什么它突出了其他领域。每次都突出显示相同的字段。它们的名称与FieldModified
字段不匹配。
Private Sub Form_Load()
Dim rstForm As DAO.Recordset
Dim ctl As Control
Dim tb As Control
Dim fldName As String
Set rstForm = Forms!ChangedData.Form.Recordset
Do While Not rstForm.EOF
fldName = Me.FieldModified.value
Me.Controls(fldName).BackColor = vbYellow
rstForm.MoveNext
Loop
End Sub
编辑:我更改了代码,现在它正确地突出显示了第一行字段,但随后突出了每一行中的相同字段。
Private Sub Form_Load()
Dim rstForm As DAO.Recordset
Dim ctl As Control
Dim fldName As String
Set rstForm = Me.RecordsetClone
Do While Not rstForm.EOF
fldName = Me.FieldModified.value
Me.Controls([fldName]).BackColor = vbYellow
rstForm.MoveNext
fldName = ""
Loop
Set rstForm = Nothing
End Sub