3

I get a "User-defined type not defined" error when I execute the below code, and the

"objCon As ADODB.Connection"

is highlighted on the first line. I am trying to set a connection from Excel to Access via VBA code. Thank you for any advice!

Private objCon As ADODB.Connection Private rstRec As ADODB.Recordset Private strQry Sub Connect() Dim strConn As String Set objCon = New ADODB.Connection objCon.Mode = adModeReadWrite If objCon.State = adStateClosed Then strConn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & "C:\DB\Db.accdb;Persist Security Info=False;" objCon.ConnectionString = strConn objCon.Open End If End Sub 
6
  • 2
    Hi, have you add ActiveX inside Tools->reference? support.microsoft.com/kb/257819 Commented Dec 17, 2012 at 8:17
  • Oh my, that was it, it worked! Fabulous. Please add as an answer so I can add points for you. Commented Dec 17, 2012 at 8:25
  • 1
    I suggest closing the question, this question has been asked many time before, you can search for VBA ADODB REFERENCE on SO or Google to find the solution. :) Commented Dec 17, 2012 at 8:27
  • Cqn I close, and if so, how? Or maybe only a mod can do it? Commented Dec 17, 2012 at 8:29
  • can you see share|edit|close|delete|flag above the comments? the delete If not I can make it as an answer.. Commented Dec 17, 2012 at 8:30

1 Answer 1

6

You can do one of the following

set objCon = CreateObject("ADODB.Connection") set rstRec = CreateObject("ADODB.Recordset") 

Or in VBA Editor Tools-->Reference--> Add Microsoft ActiveX Data Object X.Y Library

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.