ADODB.Connection in Access 97

J

John

Hi

Is it possible to use ADODB.Connection in Access 97? I have placed a
reference to 'Microsoft ActiveX Data Object 2.8 Library' in references and
am using the below code but I get a 'Variable not defined' on
CurrentProject.

Dim cn As New ADODB.Connection

Set cn = CurrentProject.Connection

Thanks

Regards
 
D

Dirk Goldgar

John said:
Hi

Is it possible to use ADODB.Connection in Access 97? I have placed a
reference to 'Microsoft ActiveX Data Object 2.8 Library' in references and
am using the below code but I get a 'Variable not defined' on
CurrentProject.

Dim cn As New ADODB.Connection

Set cn = CurrentProject.Connection


In Access 97, there was no CurrentProject property or object.
CurrentProject and CurrentData were introduced with Access 2000 and the
Access Data Project.

You can use ADO, but you have to create your own connection, not piggyback
on the one Access is using.
 
D

Douglas J. Steele

That's because CurrentProject is an Access object, introduced in Access
2000, not part of ADO.

You'll have to open the connection explicitly:

Dim strConnect As String

strConnect = "Provider=Microsoft.Jet.OLEDB.3.51;" & _
"Data Source=C:\mydatabase.mdb;User Id=admin;Password=;"

cn.Open strConnect

Incidentally, it would better not to use the New keyword when declaring the
Connection object:

Dim cn As ADODB.Connection
Dim strConnect As String

strConnect = "Provider=Microsoft.Jet.OLEDB.3.51;" & _
"Data Source=C:\mydatabase.mdb;User Id=admin;Password=;"

Set cn = New ADODB.Connection
cn.Open strConnect
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top