Updating table

  • Thread starter Thread starter ohaya
  • Start date Start date
O

ohaya

Hi,

I have a table in Access where I need to update the same field in each
record, so I have loop where I step through the table, something like (doing
this from memory):

Dim db as Database
Dim rst as Recordset
..
..
LOOP:
rst.Fields ("My field") = <new value>
rst.MoveNext
if Not rst.EOF goto LOOP

I was getting an error on the rst.Fields("My field") = <new value>.
Shouldn't I be able to do this?

I've since found a better way, by doing an SQL Update, but just for my own
understanding, I'm still somewhat curious as to why the above failed?

Thanks,
Jim
 
Believe your code needs to look like the following:

Dim db as Database
Dim rst as Recordset

rst.MoveFirst
Do while not rst.eof
rst.Edit
rst.Fields ("My field") = <new value>
rst.Update
rst.MoveNext
Loop
 
Back
Top