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
Bookmarks