简体   繁体   English

ms访问 - 当我在vba中选择查询时,列为空

[英]ms access - when I select a query in vba, column is empty

When i write a select statement in vba to grab a column from a query its empty. 当我在vba中编写一个select语句来从查询中获取一个列为空时。

i have a query thats joined by multiple tables. 我有一个由多个表连接的查询。

For example if I call select query.specialcolumn from query where query.id=5 I get a blank back. 例如,如果我select query.specialcolumn from query where query.id=5调用select query.specialcolumn from query where query.id=5得到空白。 However, If I view it in the query table I see data for ID=5 with data. 但是,如果我在查询表中查看它,我会看到带有数据的ID = 5的数据。

Straight SQL in design mode also produces blanks. 设计模式下的直接SQL也会产生空白。 Only when I view the query as a whole, I can see data. 只有当我整体查看查询时,才能看到数据。

Any ideas? 有任何想法吗?

Sounds like you used "query" as the name for your saved query. 听起来像是使用“查询”作为已保存查询的名称。 And query is a reserved word, see Problem names and reserved words in Access . 查询是保留字,请参阅Access中的问题名称和保留字 It's hard predict when reserved words as object names will create problems. 当保留字作为对象名称会产生问题时,很难预测。 And I'm not confident that name is the problem here. 我不相信这里的名字就是问题。 But I would rule it out first before investigating anything else. 但是在进行其他任何调查之前,我会先将其排除在外。

Enclose query in square brackets everywhere it's referenced in the SQL. 将查询在SQL中引用的所有地方括在方括号中。

select [query].specialcolumn from [query] where [query].id=5

The square brackets will inform the db engine that query is a database object rather than the reserved word. 方括号将通知db引擎查询是数据库对象而不是保留字。

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

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