Loop/Case 语句跳过了我正在检查的值?

时间:2021-01-13 22:20:38

标签: excel vba

我有一个子程序,我想在其中使用命令按钮提交数据,并且在发送数据之前,它有一个循环来检查用户表单每个页面上的每个控件。如果控件可见,并且适合大小写,则检查它是否为空,然后将该控件名称放入数组中。

循环开始,但是一旦我遇到第一个 case 语句循环 cmb*,它就会跳过并且不进入循环。

这里发生了什么?我之前使用过 Like 运算符清除工作表上的字段,不知道为什么这不起作用..

Private Sub CommandButton1_Click()
    Dim icontrol As Control
    Dim arrBlankFields As Variant
    Dim i As Long, x As Long
    For i = 0 To Me.MultiPage1.Pages.Count
        If Me.MultiPage1.Pages(i).Visible = True Then
            For Each icontrol In Me.Controls
                If icontrol.Visible = True Then
                    Select Case icontrol.Name
                        Case icontrol.Name Like "Multi*"
                        Case icontrol.Name Like "lbl*"
                        Case icontrol.Name Like "txt*"
                            If icontrol.Value = "" Then
                                ReDim Preserve arrBlankFields(x)
                                arrBlankFields(x) = icontrol.Name
                                x = x + 1
                            End If
                        Case icontrol.Name Like "opt*"
                            If icontrol.Value = "" Then
                                ReDim Preserve arrBlankFields(x)
                                arrBlankFields(x) = icontrol.Name
                                x = x + 1
                            End If
                        Case icontrol.Name Like "cmb*"
                            If icontrol.Value = "" Then
                                ReDim Preserve arrBlankFields(x)
                                arrBlankFields(x) = icontrol.Name
                                x = x + 1
                            End If
                    End Select
                Else
                End If
            Next
        End If
    Next i
    If Len(arrBlankFields) > 0 Then
        MsgBox arrBlankFields & " fields are empty, please go back and populate before sending data"
    Else
    End If
End Sub

0 个答案:

没有答案
相关问题