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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Records with missing data 1
Strip Characters 2
Add / Update problem 3
Coding to make AddItem work for 2000 12
Trying to ApplyFilter to form 3
findfirst problem 11
no duplicate record 6
Code error 11

Back
Top