help with update

  • Thread starter Thread starter ifoundgoldbug
  • Start date Start date
I

ifoundgoldbug

Greetings.

i have a quick question could someone post some sample code which would
go through the entirity of a database and check the value of each
record in 1 field and use an if statement to change it's value.

IE.

while not db.eof

if dept = 501 then
dept = 15501
end if

loop
 
You need to specify which table within the database you want to update, and
while it would be possible to do it by looping through a recordset, it may
be significantly more efficient to do it with an update query. Something
like ...

CurrentProject.Connection.Execute "UPDATE SomeTable SET dept = 501 WHERE
dept = 15501"

If 'dept' is a text field, you'll need quotes around the values ...

CurrentProject.Connection.Execute "UPDATE SomeTable SET dept = '501' WHERE
dept = '15501'"
 
thanks that worked very well

Gold Bug
Brendan said:
You need to specify which table within the database you want to update, and
while it would be possible to do it by looping through a recordset, it may
be significantly more efficient to do it with an update query. Something
like ...

CurrentProject.Connection.Execute "UPDATE SomeTable SET dept = 501 WHERE
dept = 15501"

If 'dept' is a text field, you'll need quotes around the values ...

CurrentProject.Connection.Execute "UPDATE SomeTable SET dept = '501' WHERE
dept = '15501'"
 

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

Back
Top