0
Я пытаюсь скопировать базу данных коллекции в vba для доступа к базе данных 2010 года, ниже приведен код, который работает. Но то, что я хочу знать, - это если есть более простой или быстрый способ сделать это, особенно когда у меня будет большое количество нет или полей и записей.VBA collection to Access 2010 database
Dim plist As New partlist 'plist is a class
Dim plcol As New Collection
Sub DBInsert1()
' this function will add add 2 records from a collection to access database
Dim DB As DAO.Database
Dim RS As DAO.Recordset
plist.itemno = "1"
plist.itemname = "one"
plcol.Add plist
Set plist = Nothing
plist.itemno = "2"
plist.itemname = "two"
plcol.Add plist
'above plcol collection has a set of info
' open database
Set DB = DAO.OpenDatabase("D:\tblImport.accdb")
' open table as a recordset
Set RS = DB.OpenRecordset("Table1")
For Each plist In plcol
' add a record to the recordset
RS.AddNew
RS.Fields("itemno") = plist.itemno
RS.Fields("itemname") = plist.itemname
' write back recordset to database
RS.Update
Set plist = Nothing
Next
' important! cleanup
RS.Close
' forget to close the DB will leave the LDB lock file on the disk
DB.Close
Set RS = Nothing
Set DB = Nothing
End Sub