William
William

Reputation: 415

Opening a Password Protected Access Database Using VBScript

I have a password protected access database that needs to be updated overnight. We have written a lite Java application that takes some parameters (i.e. Macro, Path, File Type, etc) and then executes the VBScript through the command line. So I would have a way to "store" a user name and password, and then pass it to the VBScript, but so far I have not found any other postings on this that really resolves my problem. Here is the sample code of opening an access db, with a macro, and I need to get it to accept a username and password.

    Set accdbObj = Wscript.CreateObject("Access.Application")
    accdbObj.Application.Visible = True

    Message = ("Access Password Update Started With Macro...")
    LogInformation Message, Path

    accDatabase = accdbObj.OpenCurrentDatabase(Path)
    accdbObj.Run Macro

    accdbObj.Terminate
    Wscript.Quit

Keep in mind that the Path and Macro are parameters that are passed in as a string.

Upvotes: 1

Views: 9175

Answers (1)

HansUp
HansUp

Reputation: 97101

Give the OpenCurrentDatabase Method your database password as its third argument. However, OpenCurrentDatabase doesn't return anything, so I don't think it makes sense to assign its return value to accDatabase. Try it this way instead:

accdbObj.OpenCurrentDatabase Path, , "password_here"

There are 2 types of passwords for an Access db file.

  1. database password: one password which all users must supply to open the db
  2. user-level security password: a separate password for each defined user

I wrote the first part of this answer assuming you meant a database password. However, then I noticed you mentioned user name, which suggests you may be using ULS (user-level security). ULS is only supported in the older MDB db file format. With Access 2007, you may be using the newer ACCDB format which does not support ULS.

If you are actually using an MDB with ULS, you'll need a different method to open the database. You could use DBEngine.CreateWorkspace with your ULS user name and password and then call OpenCurrentDatabase within that workspace.

Upvotes: 2

Related Questions