Access 2013中的SendKeys似乎不起作用

问题描述 投票:0回答:2

我是Access的vba和mac的新手,这是我第一次在网上发帖提问。我正在使用Access 2013.我搜索了各种在线资源以获取我的答案。我认为SendKeys命令就是答案,但它对我不起作用。我不确定我做错了什么。下面概述了我要完成的工作以及不符合我预期的代码步骤。任何建议,将不胜感激。谢谢。

目的:每季度一次,我的客户将收到更新的访问数据库。每个季度的所有表名都应相同。我希望他们能够简单地运行一个宏,指定新文件的位置,然后宏更新链接表并执行我构建的所有其他查询(我的最后一部分工作)。因此,我无法工作的部分是检查“始终提示新位置框”,选中“全选”框并单击“确定”(然后单击“确定”并在客户端指定新文件后关闭)地点)。以下是我正在使用的代码。

Function Open_LinkedTableManager()

DoCmd.RunCommand acCmdLinkedTableManager 'this step works fine

'the following lines, up until Application.Run don’t appear to be
'doing anything.  The code will run, but I have to manually execute
'each of the steps I am trying to automate before it gets to the
'Application.Run step

SendKeys "%a", True ' also tried SendKeys "%(a)" and "+a", "a", etc,
'True; Alt+a checks the "Always prompt for a new location box” 
  SendKeys "%s", True ' also tried SendKeys "%(s)", True; Alt+s checks the "select all"         'box 
  SendKeys "{Enter}" ' then user specifies location of new file 
  SendKeys "{Enter}" ' click OK after receiving message "All selected linked tables        'were successfully refreshed" 
  ' click Close to close linked table manager and proceed to the next step below (not 'sure how to do this)

Application.Run ("Update_all_queries") ' this is working;

End Sub
vba ms-access access-vba
2个回答
0
投票

如果发送给自己,然后在每个sendkey后尝试DoEvents。

DoEvents功能

产生执行,以便操作系统可以处理其他事件。

句法

DoEvents( )

备注

DoEvents函数返回一个Integer,表示Visual Basic的独立版本中的打开表单的数量,例如Visual Basic,Professional Edition。 DoEvents在所有其他应用程序中返回零。

DoEvents将控制权传递给操作系统。在操作系统处理完队列中的事件并且已发送SendKeys队列中的所有密钥后,将返回控制权。

DoEvents最适用于简单的事情,例如允许用户在启动后取消进程,例如搜索文件。对于长时间运行的进程,通过使用Timer或将任务委派给ActiveX EXE组件可以更好地完成处理器的处理。在后一种情况下,任务可以完全独立于您的应用程序继续,并且操作系统采用多任务处理和时间切片。

注意事项在事件过程中暂时产生处理器时,请确保在第一次调用返回之前不再从代码的其他部分执行该过程;这可能会导致不可预测的结果。此外,如果其他应用程序在您实现控制期间可能以不可预见的方式与您的过程进行交互,请不要使用DoEvents。


0
投票

我已经解决了你的困境。我需要做的就是在调用链接表格管理器之前放置sendkey语句。见下文 - 为我工作很棒!我还能够在您的订单中添加所有命令,并且它们运行良好。祝你好运,希望这有帮助。让我知道。亚当

PS:如果您有许多表来更改路径,那么对于您迫使他们必须为其设置路径的每个表的用户而言,这将是痛苦的。

SendKeys "%s", 1

DoCmd.RunCommand acCmdLinkedTableManager
© www.soinside.com 2019 - 2024. All rights reserved.