访问VBA:在连续子表单中编辑RecordSet

时间:2017-09-01 10:24:16

标签: ms-access access-vba recordset

我正在尝试编写一个函数来遍历连续子表单中的记录,并清除特定字段中的值(Entity_Under_Consideration,它是子表单上由组合框表示的查找字段)。

以下不起作用。它也不会抛出任何错误。谁能看到我错在哪里?

Public Function clearEUCData(subform As Control)

    'take a clone of the subform's recordset
    Dim entityRecSet As Recordset
    Set entityRecSet = subform.Form.Recordset.Clone()

    'if there are any records in the subform...
    If entityRecSet.RecordCount > 0 Then

        'start with the first record
        entityRecSet.MoveFirst

        'iterate through each row, clearing the data in the EUC field
        Do Until entityRecSet.EOF

            With entityRecSet
                .Edit
                    Entity_Under_Consideration = 0
                .Update
            End With

        entityRecSet.MoveNext
        Loop

    End If

    'close and purge the cloned recordset
    entityRecSet.Close
    Set entityRecSet = Nothing

End Function

1 个答案:

答案 0 :(得分:4)

你必须更明确:

With entityRecSet
    .Edit
        .Fields("Entity_Under_Consideration").Value = 0
    .Update
End With