1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
|
Sub EdittoAccess()
' exports data from the active worksheet to a table in Access
Dim db As DAO.Database, rs As DAO.Recordset, r As Long
Set db = OpenDatabase("E:\2010\NPP\V3\UID_Info_V3.mdb")
' open the database
r = 32 ' the start row in the Excel worksheet
Set rs = db.OpenRecordset("SELECT * FROM UID_Info_V3", dbOpenDynaset)
Do While Len(Range("G" & r).Value) > 0
' repeat until first empty cell in column A
Vcel = Range("G" & r).Value
With rs
rs.FindFirst "[ID]=" & Vcel
If Not rs.NoMatch Then
.Edit ' update a record
' add values to each field in the record
.Fields("code") = Range("B" & r).Value
.Fields("ref") = Range("C" & r).Value
.Fields("NMSC") = Range("D" & r).Value
.Update ' stores the record
End If
End With
r = r + 1 ' next row
Loop
rs.Close
Set rs = Nothing
db.Close
Set db = Nothing
End Sub |
Partager