Hi All
I want to add data in Access table using values in excelsheet but it gives me runtime error 3001, arguments are of wrong type,are out of acceptable range etc..
The table is empty and I want to populate data in Reference field from the Excel sheet "Data". ANy help would be much appreciated.
I want to add data in Access table using values in excelsheet but it gives me runtime error 3001, arguments are of wrong type,are out of acceptable range etc..
The table is empty and I want to populate data in Reference field from the Excel sheet "Data". ANy help would be much appreciated.
Code:
Private Sub Workbook_Open()
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
' connect to the Access database
Set cn = New ADODB.Connection
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0; " & _
"Data Source=C:\Documents and Settings\Desktop\FLLiteratureSystem.mdb;"
Set rs = New ADODB.Recordset
Dim ws As Worksheet
Dim i As Long
[COLOR="#FF0000"]rs.Open tblLiterature, cn, adOpenKeyset, adLockOptimistic, adCmdTable[/COLOR]
Set ws = ThisWorkbook.Worksheets("Data")
For i = 6 To 107
With rs
.addnew
.fields("Reference") = ws.Cells(i, "B").Value
.Update
End With
Next i
rs.Close
cn.Close
Set rs = Nothing
Set cn = Nothing
End Sub