+ Reply to Thread
Results 1 to 2 of 2

Copy from Excel to Access, delete data from DB before paste.

Hybrid View

jasocke2 Copy from Excel to Access,... 09-18-2009, 06:00 AM
jasocke2 Re: Copy from Excel to... 09-21-2009, 06:37 AM
  1. #1
    Registered User
    Join Date
    08-20-2009
    Location
    England
    MS-Off Ver
    Excel 2003
    Posts
    45

    Copy from Excel to Access, delete data from DB before paste.

    Hi,

    Got some standard code which copies data that is within Excel accross to access however I want the code to delete what ever is in the Access table before it pastes it over as at the moment it is just appending the data to it.

    Thanks,

    Sub DAOFromExcelToAccess()
    ' 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:\pathhere")
        ' open the database
        Set rs = db.OpenRecordset("Team Data", dbOpenTable)
        ' get all records in a table
        r = 2 ' 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("Name") = Range("A" & r).Value
                .Fields("Team") = Range("B" & r).Value
                .Fields("Dept") = 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
    End Sub

  2. #2
    Registered User
    Join Date
    08-20-2009
    Location
    England
    MS-Off Ver
    Excel 2003
    Posts
    45

    Re: Copy from Excel to Access, delete data from DB before paste.

    Any ideas?

    Thanks

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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