word 2007 vba adodb.connection error

Posted on 2009-02-23
Last Modified: 2012-06-27
Hello experts,

I have a word 2007 document which contains vba code that is executed when the document is opened. The vba code sets up a connection to a db and reads out some values.
Now I get an error in the line:
Dim cnArthro As ADODB.Connection

The error says:
"Compile error. User defined type not defined"

And this is weird because I have other word documents which contain the exact same codepart - and they work.

Does anybody have a clue what the problem is here?

Thanks a lot for your help
Private Sub Document_Open()

Dim nFileNum As Integer, sID As String

nFileNum = FreeFile

'------------------------Pfadname HIER ändern---------------------------

Open "\\my_server\Docs\temp.txt" For Input As nFileNum

'Auslesen der ID aus dem Textfile

Line Input #nFileNum, ID

'Auslesen des gewünschten Drucks aus dem Textfile

Line Input #nFileNum, Druck

'Variable für die ID

Dim KundeID As Integer

KundeID = CInt(ID)

'Variable für den gewünschten Ausdruck

Dim DruckID As Integer

DruckID = CInt(Druck)

' Create a connection object.

Dim cnArthro As ADODB.Connection

Set cnArthro = New ADODB.Connection

' Provide the connection string.

Dim strConn As String

Open in new window

Question by:arthrex
    1 Comment
    LVL 4

    Accepted Solution

    Have you selected Microsoft ActiveX Data Objects 2.x in Tools->References (in vba editor) ?

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Join & Write a Comment

    When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
    Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
    Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
    This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now