【问题标题】:How to check if "all" Textboxes are empty (not individual ones)如何检查“所有”文本框是否为空(不是单独的)
【发布时间】:2014-06-05 06:40:57
【问题描述】:

我在 MS.Excel (VBA) 中有一个包含两个多页的表单。两个多页上都有多个文本框。第二页上的文本框都以“txtM”开头加上一个升序数字(txtM1、txtM2 等)。在“保存”时,如果第二个多页(索引 = 1)上的所有文本框都是空的,我只想记住用户。如果其中一些是空的,但一组完整的 emtpy 文本框提示用户只是忘记点击多页的第二个“选项卡”,这完全没问题。

我已经尝试了一些方法(见下文),但到目前为止还没有找到合适的解决方案。

For Each crtl In Me.Controls
    If crtl.Name Like "txtM*" Then
        If crtl.Value = "" Then
            MsgBox "dont forget .... blablabla"
                Me.MultiPage1.Value = 1
            Exit Sub
        End If
    End If
Next

谢谢和问候, 偶们

【问题讨论】:

    标签: vba loops excel foreach


    【解决方案1】:

    我会这样做:

    Dim allEmpty As Boolean
    allEmpty = True
    
    For Each crtl In Me.Controls
        If crtl.Name Like "txtM*" Then
            If Trim(crtl.Value) <> "" Then
                allEmpty = False
                Exit For
            End If
        End If
    Next
    
    If allEmpty Then
        MsgBox "dont forget .... blablabla"
        Me.MultiPage1.Value = 1
        Exit Sub
    End If
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-09
      • 1970-01-01
      • 2010-12-06
      • 1970-01-01
      • 2013-05-28
      • 1970-01-01
      相关资源
      最近更新 更多