Look at every field in the record

  • Thread starter Thread starter MAB
  • Start date Start date
M

MAB

Is there a way to tell Access VB XP to look at every field in a record and
look for a value? For example, I have 30 fields in my record. If any one of
them (or all of them , or any number of them) is equal to a certain value
(say 5000) I want it to change the field to zero.

I can go down through each record fine by using the Do While Not .EOF /Loop
routine. But is there a way for it to look at every field without having to
name each field in the code?

Thanks!
 
try this

This goes trough all fields al records on table1 and changes 5 to 0. If you
have a lot of records you'll want to add some transactions and do it in
batches.

Sub test()
On Error Resume Next
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim fld As DAO.Field
Set db = DBEngine(0)(0)
Set rst = db.OpenRecordset("Table1")
While Not rst.EOF
For Each fld In rst.Fields
If fld.Value = 5 Then
rst.Edit
fld.Value = 0
rst.Update
End If
Next
rst.MoveNext
Wend
Set rst = Nothing
Set db = Nothing

End Sub



Rodrigo.
 
Back
Top