简体   繁体   English

MS Access:带“&”号和文本的VBA SQL更新查询

[英]MS Access: VBA SQL Update Query with Ampersand and Text

I have a small syntax problem that I'm hoping someone will help me out with. 我有一个小的语法问题,希望有人能帮助我。 I need to run a query in MS Access VBA where the record descriptors in Column 2 are updated with two characters from the Left in Column 1 - AND - the text "On0". 我需要在MS Access VBA中运行查询,其中第2列中的记录描述符使用第1列中的左起两个字符-和-文本“ On0”进行更新。

I know there's a simple fix like a single apostrophe around a portion of the code, but I've hit a roadblock. 我知道有一个简单的解决方法,例如在部分代码中使用单撇号,但是遇到了障碍。 Any thoughts? 有什么想法吗?

DoCmd.RunSQL "Update [Table1] SET [Table1].[New Col 2] = Left([Table1].[Old Col 1],2) & "On0";" 

答案是在文本周围放置一个单引号,因此字符串应如下所示:

DoCmd.RunSQL "Update [Table1] SET [Table1].[New Col 2] = Left([Table1].[Old Col 1],2) & 'On0';"

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

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