Vba 循环浏览表单上的对象(一个特定文本框除外)

Vba 循环浏览表单上的对象(一个特定文本框除外),vba,ms-access,ms-access-forms,Vba,Ms Access,Ms Access Forms,除了一个特定的文本框(其中包含OpenArgs)之外,我想在表单中遍历所有文本框和cbo。我想标识所有字段以确保它们都已填写,但这是一个未绑定表单,有时表单中不会有OpenArgs 即使VBA中的值不是一个下拉选项,它也可以工作,只是不使用VBNull字符串考虑它为空。我一直得到n=0 Dim ctl As Control Dim n As Integer n = 0 For Each ctl In Me.Controls If ctl.Name <> "txt_Open

除了一个特定的文本框(其中包含OpenArgs)之外,我想在表单中遍历所有文本框和cbo。我想标识所有字段以确保它们都已填写,但这是一个未绑定表单,有时表单中不会有OpenArgs

即使VBA中的值不是一个下拉选项,它也可以工作,只是不使用VBNull字符串考虑它为空。我一直得到n=0

Dim ctl As Control
Dim n As Integer

n = 0

For Each ctl In Me.Controls
    If ctl.Name <> "txt_OpenARgs" Then
        Select Case ctl.ControlType
                    Case acTextBox, acComboBox ' adjust to taste
                        If ctl.Value = vbNullString  Then
                            n = n + 1
                            Debug.Print n
                        End If
        End Select
    End If
Next ctl

If n > 0 Then
    MsgBox "All fields must be populated before saving.", vbOKOnly, "Missing Data"
Else
Dim ctl作为控件
作为整数的Dim n
n=0
对于Me.Controls中的每个ctl
如果ctl.Name“txt_OpenARgs”,则
选择Case ctl.ControlType
Case acTextBox,acComboBox‘根据口味调整
如果ctl.Value=vbNullString,则
n=n+1
调试打印
如果结束
结束选择
如果结束
下一个ctl
如果n>0,则
MsgBox“保存前必须填充所有字段”,vbOKOnly,“缺少数据”
其他的
…我需要使用:


如果ctl.Value&vbNullString=“”,则尝试Nz而不是vbNullString

Dim ctl As Control
    Dim n As Integer

    n = 0

    For Each ctl In Me.Controls
        If ctl.Name <> "txt_OpenARgs" Then
            Select Case ctl.ControlType
                        Case acTextBox, acComboBox ' adjust to taste
                            If Nz(ctl.Value,"") = "" Then
                                n = n + 1
                                Debug.Print n
                            End If
            End Select
        End If
    Next ctl

    If n > 0 Then
        MsgBox "All fields must be populated before saving.", vbOKOnly, "Missing Data"
    Else
Dim ctl作为控件
作为整数的Dim n
n=0
对于Me.Controls中的每个ctl
如果ctl.Name“txt_OpenARgs”,则
选择Case ctl.ControlType
Case acTextBox,acComboBox‘根据口味调整
如果Nz(ctl.Value,“”“”),则
n=n+1
调试打印
如果结束
结束选择
如果结束
下一个ctl
如果n>0,则
MsgBox“保存前必须填充所有字段”,vbOKOnly,“缺少数据”
其他的