I currently use Microsoft Office 2007 and have linked an Access 2007 Database to Excel 2007 Database. So far so good. I can update the Access Database and it shows automatically in the Excel file. Here is where I have the problem.
When I try to update an Access Database from within Excel; I keep getting the runtime 3251 Error. =>runtime error now resolved but NEW issue regarding a NULL value when im trying to add data?
Sub ADODBExcelToAccess()
'Collecting data from the
Dim cn As ADODB.Connection, rs As ADODB.Recordset, r As Long
'---NOTE: Sheet is set to auto refresh data from the database on loading---
' connect to the Access database
Set cn = New ADODB.Connection
cn.Open "Provider=Microsoft.ACE.OLEDB.12.0; " & _
"Data Source=" & Application.ActiveWorkbook.Path & "\linktest.accdb;"
' open a recordset (i.e. a table)
Set rs = New ADODB.Recordset
rs.Open "linktest", cn, adOpenKeyset, adLockOptimistic, adCmdTable
' all records in a table
For i = 4 To 16
x = 0
Do While Len(Range("K" & i).Offset(0, x).Formula) > 0
With rs
'create a new record
.AddNew
.Fields("ID") = Range("A1" & i).Value
.Fields("PriceID") = Range("B1").Value
.Fields("ProductCode") = Range("C1").Value
.Fields("Price") = Range("D1" & i).Value
.Fields("CurrencyType") = Range("E1").Value
.Fields("Type") = Range("F1").Value
.Fields("Production") = Range("G1" & i).Value
.Fields("Quantity") = Range("H1" & i).Value
.Fields("Details") = Range("I1" & i).Value
.Fields("DateUpdated") = Range("J1" & i).Value
.Fields("Setup") = Range("K1" & i).Value
' stores the new record
.Update
End With
x = x + 1
Loop
Next i
rs.Close
Set rs = Nothing
cn.Close
Set cn = Nothing
End Sub
The current reference library that I'm using is Active X Data Objects 2.1 Library.