Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I use OpenCurrentDatabase on a secured database 2

Status
Not open for further replies.

FancyPrairie

Programmer
Oct 16, 2001
2,917
US
I want to use Automation to open a secured database. Note that the secured database does not use the same workgroup my application is running in. For example, db1.mdb (uses System.mdw) trys to open a form in db2.mdb (which uses a different mdw file).

Here's some of my code:

Dim appAccess As Access.application
Set appAccess = CreateObject("Access.Application")

appAccess.OpenCurrentDatabase "db2.mdb"

appAccess.Docmd.OpenForm "Myform"

The error I get via the OpenCurrentDatabase is:

----------------------------------
Error Number 7866

Microsoft Access can't open the database because it is missing or open exclusively by another user.
----------------------------------

In my case, the database is not missing nor opened by another user.

I don't care if I have to log in or not, I just want it to work.

By the way, I'm not using automation to open a form, I'm actually trying to retrieve the databases references.
 
Might try something like:

Dim RetVal


RetVal = Shell("C:\Program Files\Microsoft Office\Office\MSACCESS.EXE /wrkgrp YourWorkgroupPath.mdw YourDatabasePath.mdb", 3)
 
I had tryed the Shell command prior to posting and couldn't get it to do what I wanted. However, because you suggested it also, I gave it another try. I can't seem to get it to work. My goal was to try to retrieve the References of the Shelled database. OpenCurrentDatabase works great as long as the database is not secured.

Any other ideas?
 
If you want to shell a secured database, you may need to add some command line parameters, such as:

&quot;<AccessPath>&quot; &quot;<DbPath>&quot; /wrkgrp &quot;<wkgrp path>\system.mdw&quot; /user <username> /pwd <password>

This of course results in the unsavory necessity to hardcode user names and passwords into the database. I have found, however, that you can shell out to a database with the current user name and it will ask for the password.

Some information you can get from access, e.g.

AccessPath: not sure, but it might be available
Db Path: currentdb.name
wrkgrp path: dbengine.SystemDB
user name: dbengine.Workspaces(0).UserName
 
Maybe something like:


Dim wks As Workspace
Dim db As Database
DBEngine.SystemDB = “c:\secureddb path.mdw”
Set wks = DBEngine.CreateWorkspace(“”, “Username”, “password”)
Set db = wks.OpenDatabase(“c:\secureddb.mdb”)

'Do something here
 
The CreateWorkspace gives me an error if I put in a valid name and password (&quot;Not a valid account name or password&quot;). However, if I put in Admin as the user, then it tells me I don't have the necessary priveledges to access the database.

Even if I got it working, how's that going to give me the References defined in the secured database?

The following works when opening an unsecured database.

Dim ref As Reference
Dim appAccess As Access.application

Set appAccess = CreateObject(&quot;Access.Application&quot;)

appAccess.OpenCurrentDatabase &quot;c:\dev\db2.mdb&quot;
For Each ref In appAccess.References
Debug.Print ref.FullPath
Next

appAccess.CloseCurrentDatabase

 
How did you find that? I've searched all over the place trying to find that code. Guess I just didn't use the right keywords. I found several that used the Shell method, but the key to making it work was the GetObject statement.

Thanks alot Rick39. Here's a star.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top