修复 VBA 中的类型不匹配错误 13
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/40708101/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Fixing type mismatch error 13 in VBA
提问by Wizard0800
I am new to coding and am trying to develop a userform that allows me to populate a database.
我是编码新手,正在尝试开发一个允许我填充数据库的用户表单。
I am trying to set up some validation for the data that can be input to the database through the userform.
我正在尝试为可以通过用户表单输入到数据库的数据设置一些验证。
The code I am using for this is shown below where Reg is the name of the controls on my userform.
我为此使用的代码如下所示,其中 Reg 是我的用户表单上控件的名称。
When I run this part of the code it stops on the first line and shows the Type Mismatch Error 13 message box.
当我运行这部分代码时,它停在第一行并显示 Type Mismatch Error 13 消息框。
Any help you can give would be much appreciated.
您能提供的任何帮助将不胜感激。
Sub ValidCombo1()
If Reg18.Value = "" And ((Reg17.Value <> "1" Or (Reg15.Value <> "0" Or "") Or Reg16.Value <> "A" Or Reg19.Value <> "") Or (Reg17.Value <> "" And Reg15.Value <> "" And Reg16.Value <> "" And Reg19.Value <> "")) Then
MsgBox "Invalid Foundations combination"
Reg13.Value = ""
ElseIf Reg25.Value = "" And ((Reg24.Value <> "1" Or (Reg22.Value <> "0" Or "") Or Reg23.Value <> "A" Or Reg26.Value <> "") Or (Reg24.Value <> "" And Reg22.Value <> "" And Reg23.Value <> "" And Reg26.Value <> "")) Then
MsgBox "Invalid Inverts and Aprons combination"
Reg13.Value = ""
回答by John Coleman
Your code might have other issues, but expressions like
您的代码可能有其他问题,但表达式如
Reg15.Value <> "0" Or ""
are a type mismatch. ""
is a string, not a Boolean value.
是类型不匹配。""
是一个字符串,而不是一个布尔值。
Replacing Reg15.Value <> "0" Or ""
by
替换Reg15.Value <> "0" Or ""
为
Reg15.Value <> "0" And Reg15.Value <> ""
(which I think is your intention) will eliminate those type mismatches.
(我认为这是您的意图)将消除这些类型不匹配。