Hi everybody
I am going to update table1 from table2 but I face an error said
"Run-time error'-2147417848(80010108)'
Method 'Fields' of object 'Recordset2' failed"
Can any body help me in that???
Code:
Private Sub updateTable(tbl11 As String, tbl22 As String)
Dim dbs11, dbs22 As DAO.Database
Dim rs11, rs22 As DAO.Recordset
Dim c1, c2 As Integer
Dim f As Boolean
f = False
Set dbs11 = CurrentDb
Set dbs22 = CurrentDb
Set rs11 = dbs11.OpenRecordset(tbl11, dbOpenDynaset, dbOpenDynamic)
Set rs22 = dbs22.OpenRecordset(tbl22, dbOpenDynaset, dbOpenDynamic)
If rs11.EOF Then Exit Sub
With rs11
Do While Not .EOF
For c1 = 0 To dbs11.Recordsets.Count - 1
f = False
For c2 = 0 To (dbs22.Recordsets.Count - 1) Or f = True
If .Fields(0) = rs22.Fields(0) And .Fields(1) = rs22.Fields(1) And .Fields(2) = rs22.Fields(2) Then
rs22.Fields(3).Value = .Fields(3).Value
rs22.Fields(4).Value = .Fields(4).Value
rs22.Fields(5).Value = .Fields(5).Value
f = True
End If
Next
rs22.AddNew
For c = 0 To .Fields.Count - 1
rs22.Fields(c) = .Fields(c)
Next
rs22.Update
'rs22.MoveNext
'rs11.MoveNext
Next
Loop
End With
rs11.Close
rs22.Close
End Sub