INSERT INTO 语句访问 VBA
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15593596/
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
INSERT INTO Statement Access VBA
提问by user2203473
Ok, I'm fairly new to Access. What I'm attempting to accomplish is using a command button to insert short text to a specific field within a table. So for example, in my Master form I'd like to have a command button, that when pushed, inserts the text "A1" into the Location field in my Master Inventory table. I tried accomplishing this by using the INSERT INTO statement, but I had no luck. Is this the best way to do it, or is there a simpler way? If it's the best way, then what am I doing wrong? Here is the code I used:
好的,我对 Access 还很陌生。我试图完成的是使用命令按钮将短文本插入表中的特定字段。例如,在我的主表单中,我想要一个命令按钮,按下该按钮时,会将文本“A1”插入到我的主库存表的位置字段中。我尝试使用 INSERT INTO 语句完成此操作,但我没有运气。这是最好的方法,还是有更简单的方法?如果这是最好的方法,那我做错了什么?这是我使用的代码:
'add data to Master Inventory Table
CurrentDb.Execute "INSERT INTO MasterInventoryTable (Location) " & _
" VALUES ('A1') "
回答by sgeddes
I don't see anything wrong with your above syntax. What that attempts to do is insert a new row in your MasterInventoryTable table with the Location field set to "A1".
我看不出你上面的语法有什么问题。尝试做的是在您的 MasterInventoryTable 表中插入一个新行,并将 Location 字段设置为“A1”。
My guess is you have other columns in that table that are preventing the statement to run (what error are you receiving). Check your table design and see if any other fields are required.
我的猜测是该表中还有其他列阻止语句运行(您收到什么错误)。检查您的表格设计,看看是否需要任何其他字段。