code in a .accdb vs .adp (1 Viewer)

CanuckBuck

Registered User.
Local time
Today, 15:14
Joined
Apr 27, 2019
Messages
31
I'm converting a solution from an Access data project (.adp file extension) to an Access database (.accdb file extension).

In my .adp file I have a bit of like so;

Code:
Dim con As ADODB.Connection

<Some code>

Set con = New Connection

<Some code>

In my .adb file this code works fine (has done so for years).

I thought that I'd be able to copy this to my .accdb file, include the appropriate references (which I have done, as far as I can tell) and that this code would work.

When I run this code in my .accdb file I get an error message saying

"Compile Error: Invalid use of New keyword"

Does anyone know why this is happening?

If it would help, I can include the whole subroutine. It's rather long. It takes a list of record Ids supplied by a user, looks up records in a database external to the one I'm developing and returns related information.

Thanks in advance for any assistance you can provide.
 

June7

AWF VIP
Local time
Today, 13:14
Joined
Mar 9, 2014
Messages
5,490
Access accdb can use Connection method. I have done that. You are missing "ADODB.". Example:

Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Set cn = New ADODB.Connection
Set rs = New ADODB.Recordset
cn.Open "Provider=Microsoft.ACE.OLEDB.12.0; Data Source='C:\Users\June\LabData.accdb'"
rs.Open "SELECT * FROM Submit", cn, adOpenDynamic, adLockPessimistic
Debug.Print rs!LabNum
 

CanuckBuck

Registered User.
Local time
Today, 15:14
Joined
Apr 27, 2019
Messages
31
Ah!

So simple when you know how :)

Thanks so much.
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 16:14
Joined
Feb 28, 2001
Messages
27,253
Yep, fairly simple. CanuckBuck, the rule of thumb is that if you qualified the datatype when you declared it then you should qualify the datatype when you instantiate it with NEW - for ANY datatype.
 

Users who are viewing this thread

Top Bottom