Hi,

I am trying to connect to a Microsoft Access DB using VB6, when I create a new connection I Dim DB as Connection, then Set db = New Connection. When the program is ran the complier doesn't recognize the word 'New'. Is there a link I can go to in order to research more about ODBC in order to connect to a Microsoft Access db using VB6. I am trying to look for the correct syntax in order to connect to the DB.

Any help would be appreciated.

Thank You,
Zoila

Dani AI

Generated

— the compiler behavior described usually means VB6 doesn't recognize the class name being instantiated, not that the keyword New itself is broken. was correct to point at References; the common fixes are (a) add the ADO library and use its full type name, or (b) avoid a name collision with a project module/class called Connection.

A minimal, correct early-bound pattern (add “Microsoft ActiveX Data Objects x.x Library” first):

Dim conn As ADODB.Connection
Set conn = New ADODB.Connection
conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Path\MyDB.mdb;Persist Security Info=False;"
conn.Open
' ...use conn...
conn.Close
Set conn = Nothing

If the database is an .accdb (Access 2007+), use the ACE provider instead:
Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Path\MyDB.accdb;

If adding the ADO reference isn’t possible, late binding avoids the compile-time type requirement:

Dim conn As Object
Set conn = CreateObject("ADODB.Connection")
conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Path\MyDB.mdb;"

Quick troubleshooting checklist:

  • Confirm “Microsoft ActiveX Data Objects x.x Library” is checked and appears above other DB libraries in Project → References.
  • Ensure no form, module or class in the project is named Connection (rename if found).
  • Match provider/driver to the file type (.mdb → Jet, .accdb → ACE) and install the correct 32-bit drivers (VB6 is 32-bit).
  • Try late binding (CreateObject) to rule out reference/version issues.

These steps resolve the vast majority of “New/Connection” compile errors when connecting VB6 to Access.

Recommended Answers

All 2 Replies

I think that's probably a problem with your references. Go to Project->References and look at your references, it should tell you if something is missing. and if you're using ado, make sure you're using adodb.connection

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.