循环浏览窗体中的活动记录组合框



>我有一个连续的表单,每条记录中有 5 个组合框。当我单击活动记录中的按钮以查找这些框是否不为 null 时,如何遍历这些框中的每一个。我只想循环访问活动记录,而不是整个记录集。

试试这个

 Dim ctl As Control
    For Each ctl In Screen.ActiveControl.Parent
       If TypeName(ctl) = "ComboBox" Then
          If IsNull(ctl) Then
            MsgBox ctl.Name & " combo is null"
          Else
            MsgBox ctl.Value
          End If
       End If
    Next

如果组合框具有相似的名称,如 cboTest1、cboTest2 等,如下所示:

For Each x = 1 to 5
    If IsNull(Me("cboTest" & x)) Then
        MsgBox "Combobox " & x & " needs data selected."
    End If
End If

最新更新