Hi,
I have two arrays, first with names of fields and second with values which I want to add to my recordset. But my code doesn't work. Is possible to do it by this way?
In line
Problem can by in square brackets. When I write
I have two arrays, first with names of fields and second with values which I want to add to my recordset. But my code doesn't work. Is possible to do it by this way?
In line
myR![label(i)] = data(i)
break my code with "Runtime error '3265': Item not found in this collection".Problem can by in square brackets. When I write
myR![Customer] = data(i)
(Customer is name of field) code is working. From my code is output myR!["Customer"] = data(i)
. I don't know how to solve it. Can you help me?
Code:
Sub AddNewItem(table, data, label)
Dim myR As Recordset
Set myR = CurrentDb.OpenRecordset(table)
myR.AddNew
For i = 0 To UBound(data) - 1
myR![label(i)] = data(i)
Next
myR.Update
myR.Close
Set myR = Nothing
End Sub