Export Excel 2010 Worksheet to Access 2010 Table VBA

JStellato

Board Regular
Joined
Nov 6, 2010
Messages
55
Hello,

I need to export a worksheet to an access table. I found this sample code

Code:
' exports data from the active worksheet to a table in an Access database
' this procedure must be edited before use
Dim db As Database, rs As Recordset, r As Long
    Set db = OpenDatabase("C:\Users\root\desktop\Test.accdb")
    ' open the database
    Set rs = db.OpenRecordset("TableName", dbOpenTable)
    ' get all records in a table
    r = 3 ' the start row in the worksheet
    Do While Len(Range("A" & r).Formula) > 0
    ' repeat until first empty cell in column A
        With rs
           .AddNew ' create a new record
            ' add values to each field in the record
            .Fields("FieldName1") = Range("A" & r).Value
            .Fields("FieldName2") = Range("B" & r).Value
            .Fields("FieldNameN") = Range("C" & r).Value
            ' add more fields if necessary...
            .Update ' stores the new record
        End With
        r = r + 1 ' next row
    Loop
    rs.Close
    Set rs = Nothing
    db.Close
    Set db = Nothing

However I get the message "Unrecognized Database Format" most likely because this code was written for .mdb file structure. So how do I accomplish the same task with Access and Excell 2010?
 

Some videos you may like

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.

Watch MrExcel Video

Forum statistics

Threads
1,109,204
Messages
5,527,401
Members
409,760
Latest member
zeeshansyed

This Week's Hot Topics

Top