PowerShell - application.opencurrentdatabase password prompt

Gary Mercer 96 Reputation points
2021-05-19T10:24:07.757+00:00

I'm using PowerShell to connect to a MS Access database stored on a UNC to run a macro. This is the code I'm using...

$MsAccess = New-Object -ComObject Access.Application
$MsAccess.OpenCurrentDatabase('\*************************\db.accdb', $False, 'password')
$MsAccess.Visible = $true
$MsAccess.Application.DoCmd.RunMacro("Macro1")
$MsAccess.CloseCurrentDatabase()
$MsAccess.Quit()

The password I'm supplying is correct as it works when I manually open the database. When I run this code I'm still being prompted to supply the password for the database...

97902-image.png

Using the same code works for other password protected databases but just not on this one.

Any help is greatly appreciated.

Windows for business | Windows Server | User experience | PowerShell
0 comments No comments
{count} votes

Answer accepted by question author
  1. Gary Mercer 96 Reputation points
    2021-05-20T15:20:16.11+00:00

    Just in case anybody stumbles across this, always double check the permissions on the UNC folder where the database is stored!

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.