运行DoCmd.RunSavedImportExport的更好方法

时间:2017-10-04 18:39:42

标签: vba excel-vba ms-access access-vba excel

目前的情况是我有我的机器(C :)启动脚本/宏"开始"这会在共享驱动器(Q:\ Database.accdb)上打开访问数据库并运行许多规范来更新表(DoCmd.RunSavedImportExport)并从前端(Q:\ Dashboard.accdb)运行许多规范来生成"报告" (DoCmd.RunSavedImportExport)。我似乎无法让两者都执行100%的时间而不会出现各种错误。

目前我已设法让第一组DoCmd.RunSavedImportExport正常运行,但当我尝试启动下一组时,我一直收到以下错误:

运行时错误' 462'

远程服务器计算机不存在或不可用。

我想说问题是我正在获得某种锁定,但我正在打开一个全新的文件?有什么帮助吗?

Public Function Start()

Dim appAccess As Access.Application
Set appAccess = CreateObject("Access.Application")
appAccess.OpenCurrentDatabase "Q:\Database.accdb"
appAccess.Application.Visible = True

DoCmd.RunSavedImportExport "CoolUploadToDB1"
DoCmd.RunSavedImportExport "CoolUploadToDB2"

KillProcess "MSACCESS.exe"
ExportReports

End Function

Public Function ExportReports()

Dim appAccess As Access.Application
Set appAccess = CreateObject("Access.Application")
appAccess.OpenCurrentDatabase "Q:\Dashboard.accdb"
appAccess.Application.Visible = True
Application.Wait (Now + TimeValue("0:00:05"))

#Consistently works up until here:
#Gives error: Run time error '462': The remote server machine does not exist or is unavailable.

DoCmd.RunSavedImportExport "ExportCoolReport1"
CoolFuncToAnnoySomePeopleWithReport "OneGuyITotallyHate@coolcompany.com"

appAccess.CloseCurrentDatabase
appAccess.Application.Quit
Set appAccess = Nothing
Application.DisplayAlerts = True

End Function

0 个答案:

没有答案