【问题标题】:Access VBA: Editing a RecordSet in a continuous subformAccess VBA:在连续子窗体中编辑 RecordSet
【发布时间】:2017-09-01 10:24:16
【问题描述】:

我正在尝试编写一个函数来循环遍历连续子表单中的记录并清除每个记录的特定字段(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

【问题讨论】:

  • 更新克隆的记录集后,您似乎没有刷新表单记录集?
  • 但更改仍在应用到表单的记录集。这是怎么回事?
  • 忍者访问侏儒在后台工作?记录集更新通常会立即显示,但并非总是如此……可能取决于它是本地表还是链接表的连接方式。

标签: ms-access vba recordset


【解决方案1】:

你必须更明确:

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

【讨论】:

  • 最好将Option Explicit 添加到所有代码模块。该选项会导致未声明变量Entity_Under_Consideration 出现错误。在 VBA IDE 中,您还可以设置 Tools | Options | Editor | Code Settings | [x] Require Variable Declarations,它会自动将 Option Explicit 添加到所有新的代码模块。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-05-10
  • 2013-11-06
  • 2017-02-23
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多