问题描述
我正在使用Excel表单,用户可以在其中添加/更新电子表格。如果文本框为空,我具有CheckForErrors的验证功能。但是,如果用户输入空格,则验证无效。因此,我试图使用Trim(Ctrl.Value)=“”。在我的机器上运行正常,但在用户的机器上抛出错误,
"Compile error: Can't find project or library".
请建议是否有Trim()的替代方法或验证空间,制表符等输入的其他方法。 (我试图搜索它,但我不想让用户去引用并选中“缺少”的引用。)
Function CheckForErrors() As Integer
Dim ErrorsFound As Integer
Dim CompletedCodes As Integer
Const CodesFields As Integer = 5
Dim aDecimal As Double
Dim Ctrl As MSForms.Control
ErrorsFound = 0
CompletedCodes = CodesFields
For Each Ctrl In CodesForm.Controls
Select Case TypeName(Ctrl)
Case "TextBox"
'If the text Box is empty
If Ctrl.Value = "" Then
'-> If Trim(Ctrl.Value) = "" Then 'if space was entered
' If (Len(Trim(Ctrl.Value)) = 0) Then
'If the text Box is not optional i.e. it must contain something
If Ctrl.Tag <> "Optional" Then
FlagError Ctrl
ErrorsFound = ErrorsFound + 1
Else
ClearError Ctrl
'At this point we have an empty Codes field.
'Record this for Now and we'll check again later
CompletedCodes = CompletedCodes - 1
End If
Else
If Ctrl.Name = "ABC" Or Ctrl.Name = "XYZ" Then
ClearError Ctrl
Else
FlagError Ctrl
ErrorsFound = ErrorsFound + 1
End If
End If
End Select
Next Ctrl
'If all Codes fields are empty
If CompletedCodes = 0 Then
'Check each Codes field and flag the ones in error
For Each Ctrl In CodesForm.Controls
Select Case TypeName(Ctrl)
Case "TextBox"
If Ctrl.Value = "" And Ctrl.Tag = "Optional" Then
FlagError Ctrl
End If
End Select
Next Ctrl
CheckForErrors = 1
Else
CheckForErrors = ErrorsFound
End If
End Function
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)