Recordset循环突出显示未定义的字段

时间:2019-07-10 17:23:59

标签: vba ms-access

我以连续的形式突出显示字段,字段名称来自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

0 个答案:

没有答案