Slette data i access
Hej!Jeg har fået hjælp til denne lille makro, der overfører data fra excel til access.
den virker perfekt, men jeg ville gerne have slettet indholdet inden nye data bliver overført.
Jeg vil gerne have slettet alle poster, hvor Field1 = "A10".
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:\db2.mdb")
' open the database
Set rs = db.OpenRecordset("Ssalg", dbOpenTable)
' get all records in a table
r = 10 ' 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("Field1") = Range("A" & r).Value
.Fields("Field2") = Range("B" & r).Value
.Fields("Field3") = 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