Transfer data from Excel to Access
I have this code below, which uses DAO to automatically transfer data from Excel to Access.
Can someone explain what the difference is from DAO and ADO? If I was to do the same project using ADO how could I do this? and the other issue is that the users that will be using the Excel report will not have MS Access installed on there PC. Does this change the way the code has to be written?
Sub AddToMDB()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim r As Long
Set db = DAO.DBEngine.OpenDatabase("D:\Work\MILtd.mdb")
Set rs = db.OpenRecordset("tblExcelImport", dbOpenDynaset)
r = 2
Do While Len(Range("A" & r).Formula) > 0
rs.AddNew
rs![Day of Week] = Range("A" & r).Value
rs!WeekNum = Range("B" & r).Value
rs!Week = Range("C" & r).Value
rs!ConcatDate = Range("D" & r).Value
rs![HEAT - BCC] = Range("E" & r).Value
rs![HEAT - Leeds] = Range("F" & r).Value
rs![JD Heating] = Range("G" & r).Value
rs![RG Francis] = Range("H" & r).Value
rs!TotalDay = Range("I" & r).Value
rs![Weekend?] = Range("J" & r).Value
rs!User = "Jez L"
rs.Update
r = r + 1
Loop
Set db = Nothing
Set rs = Nothing
End Sub
Thanks,
Jez
|