开发者

Scripting access to an Access file with a security Workgroup file

I am trying to script access to an Access database for use on the command line. The Access database is secured with a workgroup file.

Dim oApp, sWGF,myWS
Set sApp = CreateObject("Access.Application")
set sWGF = "C:\Users\Alan\Documents\Secured.mdw"
oApp.DBEngine.SystemDb = sWGF
WScript.echo "Workgroup " & sWGF
WScript.echo "SystemDb " & oApp.DBEngine.SystemDb
Set myWS = oApp.DBEngine.CreateWorkspace("New","Name","Password")

This code outputs the Secured.mdw filename for the workgroup, but the default System.mdw filename for the SystemDB as the output from the two WScript.echo commands. It also fails to create the workspace saying the Name and Password are wrong (although they ARE correct for the Secured.mdw file)

There are lots of references elsewhere on the net that say you can only do this as the first thing insi开发者_如何学运维de an application, but that IS what I am doing.

I am not sure what I am doing wrong. Any ideas


I think you should be using DAO and Jet directly, instead of automating Access.

  Dim objEngine
  Dim strWorgroup
  dim wrkWorkspace
  Dim db

  Set objEngine = CreateObject("DAO.DBEngine.36")
  objEngine.SystemDB = "C:\Users\Alan\Documents\Secured.mdw"
  Set wrkWorkspace = objEngine.CreateWorkspace("", "Name", "Password")
  Set db = wrkWorkspace.OpenDatabase("C:\MyDatabase.mdb")

This would bypass Access itself and use the Jet database engine directly, which seems simpler to me.

In testing this, I had some difficulty setting the SystemDB as well, but it turned out I just had to make sure I was providing a VALID one for use. The first non-default one I tried didn't work, but when I made a copy of the default one and used that, it worked.

So, I'd look to see if you've got the correct filename/path for your workgroup file, if it's the right version of Jet, and if you've got the appropriate NTFS permissions to open it.


Are sApp and oApp the same thing? You're mixing up variables.


A late addition to "I had some difficulty setting the SystemDB as well":

This worked for me:

Set objEngine = CreateObject("DAO.PrivateDBEngine.36")
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜