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
|
Sub EdittoAccess()
' exports data from the active worksheet to a table in Access
Dim db As Database, rs As 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
Do While Len(Range("G" & r).Value) > 0
' repeat until first empty cell in column A
Vcel = Range("G" & r).Value
Set rs = db.OpenRecordset("select * from [01_DE] where ((([01_DE].Id) Like " & Vcel & ")), dbOpentable")
With rs
.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 With
r = r + 1 ' next row
Loop
rs.Close
Set rs = Nothing
db.Close
Set db = Nothing |
Partager