• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 246
  • Last Modified:

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?
0
rrhandle8
Asked:
rrhandle8
  • 11
  • 7
1 Solution
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
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 ArchitectCommented:
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
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

 
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 ArchitectCommented:
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 ArchitectCommented:
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 ArchitectCommented:
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 ArchitectCommented:
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 ArchitectCommented:
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
 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

  • 11
  • 7
Tackle projects and never again get stuck behind a technical roadblock.
Join Now