3

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 inside an application, but that IS what I am doing.

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

akc42
  • 4,893
  • 5
  • 41
  • 60

3 Answers3

2

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.

David-W-Fenton
  • 22,871
  • 4
  • 45
  • 58
  • Great that solved it. The reason I am using the Application Object is that I am trying to use the scripts shown at (http://stackoverflow.com/questions/187506/how-do-you-use-version-control-with-access-development), but opening the database with DAO, and then whilst its open using the application object to OpenCurrentDatabase() works (whereas it didn't with the raw scripts). I still have to check the rest works - but I think I am on my way. – akc42 May 14 '11 at 14:41
0

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

This worked for me:

Set objEngine = CreateObject("DAO.PrivateDBEngine.36")
SomeGuyOnAComputer
  • 5,414
  • 6
  • 40
  • 72
Werner
  • 1
0

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

JeffO
  • 7,957
  • 3
  • 44
  • 53