简体   繁体   English

MS Access 2007插入查询无法执行

[英]MS Access 2007 Insert Query fails to execute

I have a simple query to insert a record into a table (P_Case table). 我有一个简单的查询来将记录插入表(P_Case表)。 I get the values from textboxes in a form (Case_Form). 我从表单中的文本框中获取值(Case_Form)。 I execute the query when clicking on a command button in the Case_Form. 我在单击Case_Form中的命令按钮时执行查询。 However, the execution fails and I get the error "Query input must contain at least on table or query"!!! 但是,执行失败,我收到错误“查询输入必须至少包含在表或查询上”!!!

INSERT INTO P_Case (Case_Date, Case_Desc, Aff_Person) 
VALUES (Forms!Case_Form![Case Date], Forms!Case_Form![Case Desc], (SELECT Person.ID FROM Person WHERE Person.National_ID=Forms!Case_Form![National ID]));

I appreciate your help.. 我感谢您的帮助..

Thanks. 谢谢。

It is been a while why I used Access but I doubt you can use subqueries in the VALUES statement. 我使用Access已经有一段时间,但我怀疑你可以在VALUES语句中使用子查询。

So try something like: 所以尝试类似的东西:

INSERT INTO P_Case (Case_Date, Case_Desc, Aff_Person)
SELECT Forms!Case_Form![Case Date]
     , Forms!Case_Form![Case Desc]
     , Person.ID 
FROM Person 
WHERE Person.National_ID=Forms!Case_Form![National ID]
);

If that not works you need to get the value from the subquery first and store it into a form variable. 如果这不起作用,您需要首先从子查询中获取值并将其存储到表单变量中。

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

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