简体   繁体   中英

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.

The field in Access is defined as Yes/No and the parameters specified as below:

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.

When I try and execute the query however, a 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 .

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).

I tried again directly in Access and the query worked. I then tried from the macro in VBA and it executed no problem.

Strange

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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