Link to home
Start Free TrialLog in
Avatar of jeffstatt
jeffstatt

asked on

Open ADO connection to CurrentDB - prevented from being opened

I have an Access database in which I need to create an ADO connection.

This is the code:

Set cn = New ADODB.Connection
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & CurrentDb.Name, "", "" 


This is the error that appears when the code is run:

"The database has been placed in a state by user 'Admin' on machine 'MYCOMPUTER' that prevents it from being opened or locked.


I am doing this wrong?  How do you create an ADO connection to the CurrentDB?
       
Avatar of KMAN
KMAN

CurrentDb is used with DAO, not ADODB.

I'm sure there is a variable to return the database path.  Looking...

K
Access.Application.name may return the value you are looking for.
Avatar of jeffstatt

ASKER

It's not the name that's the problem.

The problem is that during run time the access database is already opened by the time this code is run (just by virtue of a user opening the Access DB) - so ADO complains that the DB is already open
Are you sure the database is initially opened in "Shared mode", thus enabling the new connection?

Nic;o)
Nic
Where would I go to check that?


Select Tools/Options, under the Advanced tab there's the option "Default open mode".

But it can be set from code too...

Nic;o)
Like expected this is set as 'Shared'.
Then make sure the code isn't setting it and specify in the cn.open also the shared use.

Nic;o)
Since this software is run at customer sites around the country and multiple users are in there constantly - I can pretty much feel assured that the Access database share mode has far less to do with it than the ado connection attempt.

I guess the answer I'm looking for is whether or not VBA allows an ADO connection to CurrentDB, or if there is a property or parameter of the cn.open command that I inadvertantly have set to attempt an exclusive lock (personally I don't know that such an option exists)
As far as I can see in the help-file, only samples are published for other languages as VBA.
The .open doesn't have any additional parms, so I'm getting the impression that it's not possible.

BTW why does it has to be ADO and to the same database?

Nic;o)
Because I have to call a dll that has the ADO connection object as a parameter
Woul opening another (dummy) database to create the connection be an option ?

Nic;o)
ASKER CERTIFIED SOLUTION
Avatar of McThud
McThud

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
oops, taht should of course, have been:

Dim cn as ADODB.Connection

set cn = CurrentProject.Connection
I knew there was a quick and easy answer to this!!!

Thanks McThud!!



(Thanks Nic for staying after it!)