Joe Howard
asked on
VBA OpenDatabase prompting for password
Hi folks,
This one got me stumped, Using the following code the user is prompted for a password even though it is supplied in the code.
1. What causes it?
2. How to prevent it?
This one got me stumped, Using the following code the user is prompted for a password even though it is supplied in the code.
1. What causes it?
2. How to prevent it?
Set dbs = OpenDatabase(Name:=strBackEnd, Options:=False, ReadOnly:=False, Connect:="MS Access;PWD=1234")
ASKER
Never got it to work in the code.
1. Password is correct (database will open when the same password is supplied to the prompt).
2. strBackEnd is the correct backend.
3. Backend works fine when opened manually.
1. Password is correct (database will open when the same password is supplied to the prompt).
2. strBackEnd is the correct backend.
3. Backend works fine when opened manually.
Are you using the Workspace object to do this:
Dim ws As DAO.Workspace
Dim dbs As DAO.Database
Set ws = DBEngine.Workspaces(0)
Set dbs = ws.OpenDatabase(blah blah)
Just for kicks, you might try it using different syntax:
Set dbs = OpenDatabase(strBackEnd, False, False, "MS Access;PWD=1234")
Named arguments shouldn't have anything to do with this, of course, but it's worth a shot.
What operating system are you on?
What environment are you using when running this code (i.e. Access, Excel, etc)?
Dim ws As DAO.Workspace
Dim dbs As DAO.Database
Set ws = DBEngine.Workspaces(0)
Set dbs = ws.OpenDatabase(blah blah)
Just for kicks, you might try it using different syntax:
Set dbs = OpenDatabase(strBackEnd, False, False, "MS Access;PWD=1234")
Named arguments shouldn't have anything to do with this, of course, but it's worth a shot.
What operating system are you on?
What environment are you using when running this code (i.e. Access, Excel, etc)?
ASKER
No I'm not using the Workspace object (but I did try and it didn't make a difference).
As you expected removing the named arguments didn't help.
Running it from Access 2010 on Windows 7.
As you expected removing the named arguments didn't help.
Running it from Access 2010 on Windows 7.
What's the path of the database (i.e. strBackEnd)? Curious as to exactly where, on the machine, it resides.
Got everything in a Trusted Location (the file at strBackend, as well as the FE where you're running the code)?
Got everything in a Trusted Location (the file at strBackend, as well as the FE where you're running the code)?
ASKER
The path is C:\Users\MacroShadow\Deskt op\Test\Ba ckend.accd b
Both front and back end are in the same folder. Folder is trusted.
Both front and back end are in the same folder. Folder is trusted.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
mbizup, turns out you were right the problem was caused by Application.CompactRepair using DBEngine.CompactDatabase instead.
Thanks
Thanks
-- Password is wrong, or has been changed.
-- You're pointed to the wrong backend (especially on Win7 with virtualized folders)
-- Backend is corrupt/faulty