Update recordset in code

K

Kim

I am trying to update a recordset without knowing the field names. I find
the field names using .field.name. See below:

For i = 2 To fldCount - 2
mastervalue = master.Fields(i - 1).Name
replicavalue = replica.Fields(i - 1).Value

master.Edit
master.mastervalue= replicavalue
master.Update



I want update master.(mastervalue) to replicavalue. I get error "Object
doesn't support this property or method" I know that the error is with
master.mastervalue= replicavalue. Any one have any ideas?

Thanks!
 
D

Dirk Goldgar

Kim said:
I am trying to update a recordset without knowing the field names. I
find the field names using .field.name. See below:

For i = 2 To fldCount - 2
mastervalue = master.Fields(i - 1).Name
replicavalue = replica.Fields(i - 1).Value

master.Edit
master.mastervalue= replicavalue
master.Update



I want update master.(mastervalue) to replicavalue. I get error
"Object doesn't support this property or method" I know that the
error is with master.mastervalue= replicavalue. Any one have any
ideas?

Thanks!

As I understand it, you want to change the value of each field in master
(except the first, and maybe some at the end) to equal the value of the
corresponding field in replica. Right? And in your loop, you've set
mastervalue to the name of the field in master, and replicavalue to the
value of the matching field. Note that you are relying on the order of
the fields to be the same in both recordsets.

If I've understood all this correctly, you *could* modify your code to
say

master.Fields(mastervalue).Value = replicavalue

However, if you can rely on the order of the fields to match, why not
just transfer the value directly using the numeric field index? As in

For i = 2 To fldCount - 2
master.Edit
master.Fields(i - 1).Value = replica.Fields(i - 1).Value
master.Update
Next i
 
K

Kim

Thanks so much. This is what I wanted.

Kim

Dirk Goldgar said:
As I understand it, you want to change the value of each field in master
(except the first, and maybe some at the end) to equal the value of the
corresponding field in replica. Right? And in your loop, you've set
mastervalue to the name of the field in master, and replicavalue to the
value of the matching field. Note that you are relying on the order of
the fields to be the same in both recordsets.

If I've understood all this correctly, you *could* modify your code to
say

master.Fields(mastervalue).Value = replicavalue

However, if you can rely on the order of the fields to match, why not
just transfer the value directly using the numeric field index? As in

For i = 2 To fldCount - 2
master.Edit
master.Fields(i - 1).Value = replica.Fields(i - 1).Value
master.Update
Next i

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 
Top