updtaes

  • Thread starter Thread starter steve
  • Start date Start date
S

steve

I wrote a bit of code that looks at a table and updates a
particular field (below). However, I'm looking for a way
to look at the entire record...not just an individual
field and make updates based on criteria. Any suggestions
appreciated....
Thanks,

Function seekchange()
Dim db As Database
Dim rst As Recordset

Set db = CurrentDb()
Set rst = db.OpenRecordset("ARI0204")

rst.MoveFirst
Do Until rst.EOF
If rst!Field10 = "ri" Then
rst.Edit
rst!Field10 = "Account Executive"
rst.Update
End If
rst.MoveNext
Loop
rst.Close
End Function
 
You can update many fields between the .Edit and .Update
methods.


db As Database
Dim rst As Recordset

Set db = CurrentDb()
Set rst = db.OpenRecordset("ARI0204")

rst.MoveFirst
Do Until rst.EOF
rst.Edit

If rst!Field10 = "ri" Then
rst!Field10 = "Account Executive"
End If
If rst!Field11 = "MM" Then rst!Field10 = "Mickey Mouse"
End If
rst.Update

rst.MoveNext
Loop
rst.Close
End Function
 
I wrote a bit of code that looks at a table and updates a
particular field (below). However, I'm looking for a way
to look at the entire record...not just an individual
field and make updates based on criteria. Any suggestions
appreciated....

It is not necessary to use any VBA code at all. Just use an Update
query; apply any criteria you like, and update whichever fields you
like. The Query can be executed from code if you wish, but it's better
to use a stored query than to open a recordset.
 
Back
Top