Results 1 to 8 of 8

Import Data from Excel into Access

Threaded View

  1. #1
    Registered User
    Join Date
    09-23-2010
    Location
    London, England
    MS-Off Ver
    2007
    Posts
    97

    Import Data from Excel into Access

    Hi,

    I'm trying to get Excel 2007 to send some data to an existing table in Access, the amount of data can vary in size so needs to be dynamic.

    Sub DAOFromExcelToAccess()
    
    ' exports data from the active worksheet to a table in an Access database
    ' this procedure must be edited before use
    Dim r As Long
    Dim conn As New ADODB.Connection
    Dim sNWind As String
    Dim rs As Recordset
    
    sNWind = _
    "C:\Documents and Settings\jonathan.broughton\Desktop\ChannelEconomics.accdb"
    
    conn.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & _
    sNWind & ";"
    Set rs = conn.OpenRecordset("ChannelGroupList", dbOpenTable)
    
    
    r = 1 ' 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("Channel Group") = Range("A" & r).Value
    
    ' add more fields if necessary...
    .Update ' stores the new record
    End With
    r = r + 1 ' next row
    Loop
    conn.Close
    Set rs = Nothing
    
    End Sub
    code currently errors on the line Set rs = conn.OpenRecordset("ChannelGroupList", dbOpenTable)
    as this is wrong, but i need to be able to open the record at this location!

    what am i doing wrong?

    thanks

    Jonathan
    Last edited by Jollyfrog; 09-28-2010 at 06:09 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1