问题描述
我寻求关于如何计划数据库(.accdb),因为我不是很舒服我已成立的过程中自动更新的意见。
I am seeking comments on how to schedule auto updates of a database (.accdb) since I am not very comfortable with the process I have set up.
目前,它的工作原理如下:
Currently, it works as follow:
- 任务计划程序调用的.bat
- 蝙蝠调用一个.vbs
- .VBS打开数据库,并调用宏
- 宏调用一个函数(VBA级)
- 的函数调用子程序更新
我认为还有相关的数据库和存储在系统上增加该程序会打破的风险太多的步骤,它需要2个外部文件(.BAT和.vbs)的事实。
I consider there are too many steps and the fact that it requires 2 external files (.Bat and .vbs) related to the database and stored on the system increase the risk that the procedure would break.
显然,(但请告诉我,我错了,我能怎样改变).VBS不能调用一个子程序,但只有宏。相同,如果用户期望输入的数据库的VB环境下的接入的宏不能调用子程序,但只有一个函数。这就是为什么我调用的函数(VBA级别)的然后调用子程序的原因。
Apparently (but please tell me that I am wrong and how I can change it) .vbs cannot call a subroutine but only a macro. Identically, an access macro cannot call a subroutine but only a function if the user is expecting to enter the VB environment of the database. This is the reason why I called a function (VBA Level) that then calls the subroutine.
希望一些你知道如何缩短步骤,最终得到的.bat和.vbs的乘坐
Hope some of you know how to shorten the steps and eventually get ride of the .bat and .vbs
推荐答案
要尽我所知为Windows计划任务做一些有用的东西在Access VBA的最短路径是:
To the best of my knowledge the shortest path for a Windows Scheduled Task to "do something useful in Access VBA" is:
在数据库中创建一个公共功能(未分)。例如:
Create a Public Function (not Sub) in the database. For example:
Option Compare Database
Option Explicit
Public Function WriteToTable1()
Dim cdb As DAO.Database
Set cdb = CurrentDb
cdb.Execute "INSERT INTO Table1 (textCol) VALUES ('sched test')", dbFailOnError
Set cdb = Nothing
Application.Quit
End Function
在数据库中创建一个宏调用该函数:
Create a Macro in the database to invoke the function:
创建一个Windows计划任务调用MSACCESS.EXE适当的参数
Create a Windows Scheduled Task to invoke MSACCESS.EXE with the appropriate parameters
在上面的对话框中的值是:
In the above dialog box the values are:
程序/脚本:
"C:\Program Files\Microsoft Office\Office14\MSACCESS.EXE"
添加参数:
C:\Users\Public\schedTest.accdb /x DoSomething
这篇关于运行Microsoft Access作为计划任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!