从命令行打开MS-Access数据库而不运行任何启动vba代码? [英] Opening an MS-Access database from the command line without running any of the startup vba code?

查看:376
本文介绍了从命令行打开MS-Access数据库而不运行任何启动vba代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法可以从命令行打开MS-Access 2003数据库,而无需运行任何启动vba代码或显示任何错误?

Is there a way to open an MS-Access 2003 database from the command line without running any of the startup vba code or displaying any errors?

我查看了 MS Access的命令行参数,但似乎没有一个用于指定您不希望任何vba代码在启动时执行.

I looked at the command line arguments for MS Access and there doesn't seem to be one for specifying that you want none of the vba code to execute on startup.

我正在使用以下代码在单独的vba数据库中打开数据库:

I'm using the following code to open up a database in a separate vba database:

Sub test()


Dim accObj As Access.application, Msg As String
Dim application As String, dbs As String, workgroup As String
Dim user As String, password As String, cTries As Integer
Dim x

Dim theDB As Database

' This is the default location of Access
application = "C:\Program Files (x86)\Microsoft Office\OFFICE11\MSACCESS.EXE"

' Use the path and name of a secured MDB on your system
dbs = "C:\ucpdatas\awashic-pc\APLReporting.mdb"

' This is the default working group
workgroup = "E:\Tickets\CSN_NotSure\Secured.mdw"
user = "aleer"
password = "****"

Debug.Print application & " " & Chr(34) & dbs & Chr(34) & " /nostartup /user " & user & " /pwd " & password & " /wrkgrp " & Chr(34) & workgroup & Chr(34), vbMinimizedFocus

x = Shell(application & " " & Chr(34) & dbs & Chr(34) & " /nostartup /user " & user & " /pwd " & password & " /wrkgrp " & Chr(34) & workgroup & Chr(34), vbMinimizedFocus)


On Error GoTo WAITFORACCESS
Set accObj = GetObject(, "Access.Application")

' Turn off error handling
On Error GoTo 0

' You an now use the accObj reference to automate Access
Debug.Print "Access is now open."

' Do Stuff...

accObj.CloseCurrentDatabase
accObj.Quit

' Close it out...
Set accObj = Nothing
Debug.Print "Closed and complete."

Exit Sub

WAITFORACCESS: ' <--- this line must be left-aligned.
' Access isn't registered in the Running Object Table yet, so call
' SetFocus to take focus from Access, wait half a second, and try again.
' If you try five times and fail, then something has probably gone wrong,
' so warn the user and exit.

'SetFocus

If cTries < 5 Then
   cTries = cTries + 1
   Sleep 500 ' wait 1/2 seconds
   Resume
Else
   Debug.Print "It didn't work"
End If

End Sub

此行...
x = Shell(application & " " & Chr(34) & dbs & Chr(34) & " /nostartup /user " & user & " /pwd " & password & " /wrkgrp " & Chr(34) & workgroup & Chr(34), vbMinimizedFocus)
原来是...
C:\Program Files (x86)\Microsoft Office\OFFICE11\MSACCESS.EXE "C:\ucpdatas\awashic-pc\APLReporting.mdb" /nostartup /user aleer /pwd *** /wrkgrp "E:\Tickets\CSN_NotSure\Secured.mdw" 2 ...在命令行上.

This line...
x = Shell(application & " " & Chr(34) & dbs & Chr(34) & " /nostartup /user " & user & " /pwd " & password & " /wrkgrp " & Chr(34) & workgroup & Chr(34), vbMinimizedFocus)
Turns out to be...
C:\Program Files (x86)\Microsoft Office\OFFICE11\MSACCESS.EXE "C:\ucpdatas\awashic-pc\APLReporting.mdb" /nostartup /user aleer /pwd *** /wrkgrp "E:\Tickets\CSN_NotSure\Secured.mdw" 2 ... at the command line.

但是,当数据库打开时,它会执行一堆vba代码并显示错误消息.

But when the database opens it executes a bunch of vba codes and displays error messages.

推荐答案

如果不运行与该数据库关联的AutoExec宏,则无法打开Access.唯一的解决方案是让AutoExec包含确定如何打开数据库的条件参数,并且如果数据库是带外壳的,则不运行命令.这将需要编辑每个数据库以包含此逻辑.

There is no way for Access to open without running the AutoExec macro associated with that database. The only solution would be to have the AutoExec contain conditional arguments that determined how the database was opened, and not run the commands if the database was shell'd. This would require editing every database to include this logic.

这篇关于从命令行打开MS-Access数据库而不运行任何启动vba代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆