简体   繁体   English

由于字段中的逗号导致MS Access 2010 SQL查询语法错误

[英]MS Access 2010 SQL Query Syntax Error due to comma in field

I've been having issues with this code I've written to update a field (txtUOM) in MS Access 2010. 我在编写用于更新MS Access 2010中的字段(txtUOM)的这段代码时遇到了问题。

Private Sub cboSelector_Change()

  Dim myItemCode As String
  Dim QfindUOM As String

  myItemCode = Me.cboSelector.Column(0)
  QfindUOM = ("SELECT item_details.uom from item_details 
              where item_details.itemCode=" & myItemCode & " end")

  DoCmd.RunSQL (QfindUOM)

End Sub

At this point, I haven't gotten around to actually updating txtUOM since the SQL won't even run. 此时,由于SQL甚至无法运行,因此我还没有真正地更新txtUOM。 The syntax error hits me,because myItemCode has commas inside (ie 822,60 or 6,01) and I can't get rid of this because the database I've been asked to work with has this as the 'item numbers' of the inventory. 语法错误令我震惊,因为myItemCode里面有逗号(即822,60或6,01),我无法摆脱它,因为我被要求使用的数据库将此作为“项目号”库存。 Any suggestions on how I might be able to manage this? 关于如何管理此问题的任何建议? I've tried adding parenthesis and apostrophes but they don't seem to help. 我试过添加括号和撇号,但它们似乎无济于事。 For example, in the case of item 6,09: 例如,对于第6,09项:

Run-time error '3075': 
Syntax error (comma) in query expression 'item_details.itemCode=6,09 end'.

There are also some items with itemCodes that don't have commas inside (ie 6909), and the error I get is as follows: 还有一些带有itemCodes的项目,里面没有逗号(即6909),我得到的错误如下:

Run-time error '3075':
Syntax error (missing operator) in query expression 'item_details.itemCode=6909 end'.

I'm guessing there's something going terribly wrong in my code and would really appreciate any suggestions you can give! 我猜想我的代码中出现了严重错误,非常感谢您可以提出的任何建议!

Thanks for taking the time to read this question! 感谢您抽出宝贵的时间阅读此问题!

Add single quotes: 添加单引号:

 QfindUOM = ("SELECT item_details.uom from item_details 
          where item_details.itemCode='" & myItemCode & "' end")

or Double, I forget with access: 还是Double,我忘记了访问权限:

 QfindUOM = ("SELECT item_details.uom from item_details 
          where item_details.itemCode=""" & myItemCode & """ end")

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

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