访问VBA:编辑连续子表单中的记录集

问题描述:

我正在尝试编写一个函数来循环连续子表单中的记录并清除特定字段中的值(Entity_Under_Consideration,这是一个由组合框表示的查找字段子表单)为每个记录。访问VBA:编辑连续子表单中的记录集

以下不起作用。它也不会抛出任何错误。任何人都可以看到我要去哪里吗?

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 
+0

你似乎并没有被刷新更新克隆记录后的形式记录? – Minty

+0

但是,这些更改仍然应用于表单的记录集。这是怎么发生的? – DrewCraven

+1

忍者访问侏儒在后台工作?记录集更新通常会立即显示出来,但并非总是如此......可能取决于它是本地表还是链接表如何连接。 – Minty

你将有更明确的:

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

向所有代码模块添加“Option Explicit”是最佳做法。该选项会导致未声明的变量“Entity_Under_Consideration”出错。在VBA IDE中,您还可以设置Tools |选项|编辑|代码设置| [x]需要变量声明,它会自动将Option Explicit添加到所有新的代码模块。 –