ADODB.Connection in Access 97

  • Thread starter Thread starter John
  • Start date Start date
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
 
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.
 
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
 
Back
Top