Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access 2010 compile error User-defined type not defined

Tags:

vba

ms-access

I converted a 2003 database to 2010 and VBA scripting created in 2003 is not working in 2010. I am getting the message that there is a Complie Error - User-defined type not defined. I do not have experience with VBA scripting and I did not create the script but understand that action that it is completing within the database. The specific item it highlights is the DIM adoConn As New ADODB.Connection.

I am including the script any assistance will be beneficial as the action that is performed is a great asset to our workflow.

Private Sub Error_code_exit(Cancel As Integer)

    On Error GoTo Error_code_exit

    Dim strSQLErrorCode As String
    Dim adoConn As New ADODB.Connection
    Dim adoRSErrorCode As New ADODB.Recordset

    Set adoConn = CurrentProject.Connection

    strSQLErrorCode = "SELECT [Error Matrix1].[Error Code], [Error Matrix1].CTC FROM [Error Matrix1];"

    adoRSErrorCode.Open strSQLErrorCode, adoConn, adOpenKeyset, adLockOptimistic

    If Not adoRSErrorCode.EOF Then

        Do

            If adoRSErrorCode.Fields("Error Code") = Me.Error_Code.Value Then
                If IsNull(adoRSErrorCode.Fields("CTC")) Then
                    Me.chkAgree = True
                    Exit Do
                End If
            End If

            adoRSErrorCode.MoveNext

        Loop Until adoRSErrorCode.EOF

    End If

    adoRSErrorCode.Close
    adoConn.Close

Exit_code_exit:
    Exit Sub

Error_code_exit:

    MsgBox Err.Description
    Resume Exit_code_exit


End Sub
like image 368
Kristen Oquinn Avatar asked May 23 '26 00:05

Kristen Oquinn


1 Answers

You need to set a reference to the ADODB library. It is :

Microsoft ActiveX Data Objects x.x Library

In the code window, choose Tools->References and scroll down to the reference you need, then tick it. You may have another problem with your code if you use DAO recordsets and they are not explicitly defined as DAO.Recordset

like image 78
Fionnuala Avatar answered May 26 '26 02:05

Fionnuala



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!