Using ADO to insert data into an Access Database from Excel?

Hello Everyone,
We have a machine that is a standard PC running Windows XP that was used to run some reports. We have decided to move the reports to an actual Server running Windows 2K3. In the process one of our Excel reports is erroring out when we try to insert the results of the report to an Access Database.

The Error is:
Compile error:
User-defined type not defined.

The adoConn As ADODB.Connection line in line 2 is highlighted. Can someone look at the code and let me know what we may be doing wrong?


Sub Insert_ExecReport_Data_Web()
    Dim adoConn As ADODB.Connection
    Dim adoRecordSet As ADODB.Recordset
    Dim sDatabaseFilename As String
    Dim sFullPathToDatabase As String
    Dim sTableName As String
    
    'set the path and table name
    sDatabaseFilename = "Database.mdb"
    sTableName = "Executive_Report_Data"
    sFullPathToDatabase = "P:\" & sDatabaseFilename
    
    'Open database connection
    Set adoConn = New ADODB.Connection
    adoConn.CursorLocation = adUseClient
    adoConn.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & _
                sFullPathToDatabase & "; User Id=admin; Password=;"
    
    'Open a recordset
    Set adoRecordSet = New ADODB.Recordset
    adoRecordSet.Open sTableName, adoConn, adOpenDynamic, adLockPessimistic
    
    'Add a new record
    adoRecordSet.AddNew
    'Record pointer is now pointing to the new record
    'Add data to the new record
    With adoRecordSet
        .Fields("Column1").Value = Range("Exec_Rpt_Data!A2").Value
        .Fields("Column2").Value = Range("Exec_Rpt_Data!B2").Value
        .Fields("Column3").Value = Range("Exec_Rpt_Data!C2").Value
        .Fields("Column4").Value = Range("Exec_Rpt_Data!D2").Value
        .Fields("Column5").Value = Range("Exec_Rpt_Data!E2").Value
        'and so on, until all data has been entered
        
        'Update database with the new data
        .Update
    End With
    
    'CleanUp
    adoRecordSet.Close
    Set adoRecordSet = Nothing
    adoConn.Close
    Set adoConn = Nothing
End Sub

Open in new window

smart2009Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

carsRSTCommented:
Did you set a reference to microsoft activeX dataobjects?

see image
8.24.jpg
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
carsRSTCommented:
Go to Tools->References and the select the version desired (see image).
0
smart2009Author Commented:
Perfect! Worked Fantastically! THX!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.