简体   繁体   English

访问是/否字段数据类型与布尔值不匹配

[英]Access Yes/No Field Data Type Mismatch with Boolean Value

Using excel VBA, I'm trying to execute a parametised query using ADO with Access 2007. 使用excel VBA,我试图使用ADO与Access 2007来执行参数化查询。

The field in Access is defined as Yes/No and the parameters specified as below: Access中的字段定义为Yes/No并指定以下参数:

If UF_Main.obCRTN.Value Then
    .Parameters.Append .CreateParameter("p18", adBoolean, adParamInput, , False)
Else
    .Parameters.Append .CreateParameter("p18", adBoolean, adParamInput, , True)
End If

Note that the control obCRTN is an OptionButton and the if statement works correctly. 请注意,控件obCRTN是一个OptionButton ,并且if语句正常工作。

When I try and execute the query however, a Data type mismatch in criteria expression. 但是,当我尝试执行查询时, Data type mismatch in criteria expression.Data type mismatch in criteria expression. error is thrown. 引发错误。 When removing the above parameters from the query and code, the query executes fine. 当从查询和代码中删除上述参数时,查询将正常执行。

According to the documentation for ADO on W3Schools , the DataType Enum for Yes/No in Access should be adBoolean . 根据W3Schools上ADO文档 ,Access中“ Yes/No的数据DataType Enum应为adBoolean

Can anyone help with why this error is being thrown? 任何人都可以帮助您解释为什么会引发此错误吗?

For some reason, I had to execute the query directly in Access (which produced a strange result and didn't actually add the record). 由于某种原因,我不得不直接在Access中执行查询(这产生了奇怪的结果,并且实际上没有添加记录)。

I tried again directly in Access and the query worked. 我直接在Access中再次尝试,查询成功了。 I then tried from the macro in VBA and it executed no problem. 然后,我从VBA中的宏尝试了一下,它没有执行任何问题。

Strange 奇怪

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM