vba ms-access:更新记录,其中某些字段 = 文本框值

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3315364/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 11:55:09  来源:igfitidea点击:

ms-access: update record where some field = textbox value

sqlms-accessvba

提问by l--''''''---------''''''''''''

can someone please help me with the following query

有人可以帮我解决以下问题吗

i need to update a datasheet (table) in access through a form:

我需要通过表单更新访问中的数据表(表):

i will have something like this

我会有这样的东西

SQLtext = "update table1 set column1="sometext" where column2=textbox1.value"
DoCmd.RunSQL SQLtext

is this possible to do?

这有可能吗?

i have a textbox on a form and when i click a button on that form i want to update data in the datasheet where one of the columns is equal to the value property of a textbox

我在表单上有一个文本框,当我单击该表单上的按钮时,我想更新数据表中的数据,其中一列等于文本框的 value 属性

thank you!

谢谢你!

回答by JohnFx

This is what you need (note the subtle change)

这就是你所需要的(注意细微的变化)

SQLtext = "update table1 set column1='sometext' where column2='" & textbox1.value & "'"
DoCmd.RunSQL SQLtext

Note: For production code you will want to escape out any single quotes in the textbox1.value string using the string replace function, otherwise you will get a SQL error whenever a user types a single quote in that field.

注意:对于生产代码,您需要使用字符串替换函数将 textbox1.value 字符串中的任何单引号转义出来,否则只要用户在该字段中键入单引号,您就会收到 SQL 错误。