Schedule Windows task to open Access database

I have the task scheduled, and it runs, but the database has a password.  Can it be opened?
rrhandle8Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Systems AnalystCommented:
You can get the idea from this:

    Dim sDbName As String
    Dim sPwdOld As String
    Dim sPwdNew As String
    Dim db As DAO.Database

    sDbName = "SomePath\MyDb.mdb"
    sPwdOld = InputBox("Old Pwd: ")
    sPwdNew = InputBox("New Pwd:")
    'sPwdOld = "old"
    'sPwdNew = "new"
   
    Set db = DBEngine.Workspaces(0).OpenDatabase(sDbName, options:=True, readonly:=False, Connect:=";PWD=" & sPwdOld & ";")
   
    db.NewPassword sPwdOld, sPwdNew
   
    MsgBox "Pwd Accepted"
    Set db = Nothing
0
rrhandle8Author Commented:
So I open another Access database which automatically opens the database I want? Clever, if I understand correctly.
0
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Systems AnalystCommented:
Well, no ...
Or maybe ... how are you trying to do it now? What is your code now for the task scheduler ?

If you use the OpenDatabase() command, you can include a password. The example above was from a little snippet I have to change a password. The most important line is the one in bold ... and overall it would boil down to just this one line of code:

DBEngine.Workspaces(0).OpenDatabase(sDbName, options:=True, readonly:=False, Connect:=";PWD=" & sPwdOld & ";")
0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

rrhandle8Author Commented:
So but it in a vbscript snippet and have the snippet called from the task scheduler?
0
rrhandle8Author Commented:
0
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Systems AnalystCommented:
Yes ... if you are using vbScript then using the Command Line would probably work ... and use the /pwd option.
0
rrhandle8Author Commented:
Something is not right here.  When I try to open from the command line, a dialog opens asking for a username and password.  The username is filled-in with the Windows User name, and the password box is empty.  This is not how it works when I double-click on the database to open it.  In this case a dialog opens that asked only for the password.

BTW: When it opens with the Windows User name, and I enter the password, it does not accepted it.
0
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Systems AnalystCommented:
Can you post the relevant code you are using?

mx
0
rrhandle8Author Commented:
One trick is to open it from another database: http://support.microsoft.com/kb/235422

You can then use Windows Task Scheduler to open the first database, but I still cannot the macro to run.
Is my syntax wrong?

C:\Users\Owner\Documents\HAI\Clients\Ian\Database41.accdb /x "OpenPasswordProtectedDB"
0
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Systems AnalystCommented:
You have to include (first) the path to the ACCESS.EXE executable ... wherever that is on your system ... probably in C:\Program Files (x86)

Example - your location my be different ( and this is one continuous line):

"C:\Program Files (x86)\Microsoft Office\Office\msaccess.exe" "C:\Users\Owner\Documents\HAI\Clients\Ian\Database41.accdb /x OpenPasswordProtectedDB /pwd YourPassWord"
0
rrhandle8Author Commented:
Joe, I used the script you supplied.  Put into a VBS file, and into an Excel macro.
0
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Systems AnalystCommented:
oook ... and ?
0
rrhandle8Author Commented:
Let's call the password protected database Password.mdb
Tried everything that has been suggested.  Nothing worked.
So I created another database.  Let's call it Open.accdb.
I created a macro in the Open.accdb database like the one here: http://support.microsoft.com/kb/235422
I named it OpenPasswordProtectedDB.
When I run this macro, it opens the password protected database, and successfully runs the macro I want it to.
Now the last step is how to get the Windows Scheduler to open Open.accdb and run the OpenPasswordProtectedDB macro?
I typed in: C:\Users\Owner\Documents\HAI\Clients\Ian\Database41.accdb /x OpenPasswordProtectedDB
The database opens, but it cannot find OpenPasswordProtectedDB
0
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Systems AnalystCommented:
So, I am slightly confused.  Where is the vbScript coming into play?

And surely you can execute a Command Line in vbScript, right ?
(The last one I posted above)
So ... I'm not seeing why you would need to open another db first ?

In fact, as a *test* ... Open the Command Prompt dialog in Windows and just try the Command Line I posted - to confirm it opens your password protected db ... and that we have the syntax right

                                                                                         space here vv
"C:\Program Files (x86)\Microsoft Office\Office\msaccess.exe" "C:\Users\Owner\Documents\HAI\Clients\Ian\Database41.accdb /x OpenPasswordProtectedDB /pwd YourPassWord"
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rrhandle8Author Commented:
I abandoned the vbscript when I discovered I could open the database using code in another database.
Now if I can just get the Windows Task Scheduler to open the second database and run the macro that opens the other database.

When I use this  C:\Users\Owner\Documents\HAI\Clients\Ian\Database41.accdb /x OpenPasswordProtectedDB I get the error message:
Microsoft Access cannot find the object 'OpenPasswordProtectedDB'
0
rrhandle8Author Commented:
If I try your approach, the database opens but I am prompted for a username and password.  Even if I type in the password, it fails.
Normally when I open the database, their is no username requested.
0
rrhandle8Author Commented:
Image of error message http://screencast.com/t/pk2lTKFp6xF0
0
rrhandle8Author Commented:
This is what happens when I run the command in a vbs: http://screencast.com/t/dkd1iNZez2H
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.