The following code sits in an excel spreadsheet and opens an access database to insert a new record. I want to replicate this but to import into an identical SQL Server database instead.
Is anyone able to let me know how I can do the same with an identical table in SQL server with filename - C:\Documents and Settings\O\Desktop\RPData.mdf?
Many thanks,
Os
Code:
Sub DAOFromExcelToAccess()
Dim db As Database, rs As Recordset, r As Long
Set db = OpenDatabase("C:\Documents and Settings\O\Desktop\RPData.mdb")
Set rs = db.OpenRecordset("thursdaytable", dbOpenTable)
Set rs2 = db.OpenRecordset("SELECT Max([Race Number]) FROM thursdaytable")
With rs
.AddNew ' create a new record
.Fields("Race Number") = rs2.Fields(0) + 1
.Fields("osknows1") = Range("a4").Value
.Fields("osknows2") = Range("a5").Value
.Fields("buttonhole") = Range("b6").Value
.Update ' stores the new record
End With
rs.Close
Set rs = Nothing
db.Close
Set db = Nothing
End Sub
Is anyone able to let me know how I can do the same with an identical table in SQL server with filename - C:\Documents and Settings\O\Desktop\RPData.mdf?
Many thanks,
Os