我正在尝试从MS Access表单中的用户输入填充ADODB记录集。
数据类型Access表中的字段shorttext。我试图从表单输入中获取的数据也是一个文本。
queryString="select * From tableshoporder where shopordernumber=" & me.txtInputShoporder.Value
adodb.recordset.open queryString,currentdb.connection,adopendynamic,adlockoptimistic
上述查询抛出";类型不匹配错误";。
由于您声明
Access表中字段的数据类型为短文本。我试图从表单输入中获得的数据也是文本。
您需要提供由字符串分隔符包围的值,例如使用单引号:
queryString="select * From tableshoporder where shopordernumber='" & me.txtInputShoporder.Value & "'"
或双引号:
queryString="select * From tableshoporder where shopordernumber=""" & me.txtInputShoporder.Value & """"
但是,请注意,如果me.txtInputShoporder.Value
本身包含字符串分隔符,这将中断。为了避免这种情况,您可以使用Gustav的cSQL函数,也可以使用参数。