vba DoCmd.OpenQuery ("myQueryName") 不是在代码中执行而是手动工作
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11766057/
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
DoCmd.OpenQuery ("myQueryName") Not Executing in Code but Working Manually
提问by Scott Holtzman
I have inherited an Access database that I am trying to untangle so I can get it to do its intended purpose. I seem to have hit a relatively simple snag, but I've never seen this issue before, so it's throwing me throw a loop.
我继承了一个我试图解开的 Access 数据库,这样我就可以让它达到预期的目的。我似乎遇到了一个相对简单的障碍,但我以前从未见过这个问题,所以它让我抛出一个循环。
There are several statements in the vain of:
有几种说法是徒劳的:
DoCmd.OpenQuery ("myQueryName")
When I step through these in code, the code executes, but the action of the query (APPEND, UPDATE, etc) do not take place. When I run them manually, they do the necessary action.
当我在代码中逐步执行这些代码时,代码会执行,但查询操作(APPEND、UPDATE 等)不会发生。当我手动运行它们时,它们会执行必要的操作。
Can anyone offer some insight, as this really seems to be the snag that is causing the database not to do its intended purpose accurately?
任何人都可以提供一些见解,因为这似乎确实是导致数据库无法准确实现其预期目的的障碍?
Two more bits of information that may be helpful. The build is Access 2003, but I am running in Access 2010 as a 2003 database file. Also, the original author, placed notes in the queries to not run them manually. I assume this is to help alert users not to mess with things (although, it was a poor job to block query's from being run manually!!!), but I thought perhaps there's something to this that may help trigger a solution.
还有两点可能有用的信息。构建是 Access 2003,但我在 Access 2010 中作为 2003 数据库文件运行。此外,原作者在查询中放置了注释,以免手动运行它们。我认为这是为了帮助提醒用户不要弄乱事情(尽管阻止手动运行查询是一项糟糕的工作!!!),但我认为这可能有助于触发解决方案。
Thanks a ton for any help!
非常感谢您的帮助!
回答by Scott Holtzman
what do you know, I found my answer after I posted this question. And it's what I thought all along. DoCmd.OpenQuery
does not normally open a query, but not execute it. For action queries, you need db.Execute "myQueryName"
or an SQL statement with DoCmd.RunSQL
.
你知道什么,我在发布这个问题后找到了我的答案。这就是我一直以来的想法。DoCmd.OpenQuery
通常不会打开查询,但不会执行它。对于操作查询,您需要db.Execute "myQueryName"
或 带有DoCmd.RunSQL
.