so i have no real problem, just would like to know why i am getting the error
rather than updating each of the fields, would prefer to use
Code:
tmp.Update tmp.(0), Text1(0)
where the fields and values should be able to be arrays (as with addnew, which works fine)
but testing either individual fields or arrays give the error 3265
"Item cannot be found in the collection corresponding to the requested name or ordinal"
i have also tried tmp.fields(0) and tmp("fieldname")
i am able to access all fields in select queries
any suggestions?
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case. Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
I think this might be the trouble: The two optional arguments must be Variant.
Code:
Private Sub cmdUpdate_Click()
'Show use of RS.Update to update a single field at a time by ordinal.
Dim F As Long
With RS
For F = 0 To Label1.UBound
'Update by ordinal F:
.Update CVar(F), CVar(Text1(F).Text)
'This (by name) works as well:
'.Update CVar(.Fields(F).Name), CVar(Text1(F).Text)
Next
End With
Be wary of relying on default properties of objects too. There are lots of places where that can get you into trouble.
explicitly converting the fields and values to variant made no difference
your demo works perfectly, even without explicitly converting fields to variant, the only difference i see is the cursor location (useserver) in mine, so i tried changing that, but no difference
i will follow up more tomorrow
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case. Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
that is a typo in the post only, at that point i had tmp.fields(0), and i failed to remove the .with fields
i also tried
Code:
af = Array(tmp(0))
av = Array(tmp(1))
tmp.Update af, av
which of course is not the desired result, but the same error occurred anyway
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case. Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
Saves any changes you make to the current record of a Recordset object.
Syntax
recordset.Update Fields, Values
Parameters
Fields Optional. A Variant representing a single name or a Variant array representing names or ordinal positions of the field or fields you wish to modify.
Values Optional. A Variant representing a single value or a Variant array representing values for the field or fields in the new record.
....
maybe try
Code:
af = Array(0,1)
av = Array(Text1(0).Text,Text1(1).Text)
tmp.Update af, av
Last edited by DEXWERX; Sep 27th, 2016 at 09:22 AM.
thank you for your inputs i have now figured what i was doing wrong, so this specific error is resolved, i now have another error, so i will stay with editing the fields, then update without arguments
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case. Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete