run a macro in another database

Jaye7

Registered User.
Local time
Today, 18:21
Joined
Aug 19, 2014
Messages
205
I am trying to run a macro in a password protected database, however the script doesn't actually enter the password in the password section so unless I manually key it in I can not open it.

The password is correct.

Code:
Sub Test1()
Dim app As Access.Application
    
    'Start a new MSAccess application
    Set app = New Access.Application
    
    'Open the remote database and run a macro, then close the remote database
    With app
        .OpenCurrentDatabase "X:\Test\Test1.mdb", True, "helpme"
        .DoCmd.RunMacro "UTTest1"
        '.CloseCurrentDatabase
    End With
    
    'Quit the spawned app
    'app.Quit acQuitSaveNone
    'Set app = Nothing
    
    'Quit the current app
    'Application.Quit acQuitSaveNone
End Sub
 
you could try replacing
.OpenCurrentDatabase .....
with
Code:
dim db as dao.database
Set db = app.openDatabase("PathAndNameOfDdatabase.accdb",False,True,"MS Access;pwd=yourPassword")

This will create a reference to your password protected database but I doubt you can run a macro like this.

As an alternative, you could have the macro run via Autoexec in the database or maybe set a timer in a form to run the macro.
 
Thanks arnelgp, I tried a similar script previously but it didn't work, the user and password dialog box appears with no value in the password.
 
Sorry Cronk, that doesn't work either
 

Users who are viewing this thread

Back
Top Bottom