record set to change field (1 Viewer)

bonekrusher

Registered User.
Local time
Today, 15:28
Joined
Nov 19, 2005
Messages
266
Hi all, I am trying to update a field based on another field through a record set. In this code I want to update SYS if Element_label is like 3 (the field has values 3.1, 3.3.1 etc...). Am I going about this the right way?

Code:
Dim rst As DAO.Recordset
Set rst = CurrentDb.OpenRecordset("description")
While Not rst.EOF
    With rst
    If rst![Element_Label] Like 3 Then
    rst![sys] = 3
   
    Else: End If
      End With
rst.MoveNext

Wend
 

bigstav

Registered User.
Local time
Today, 23:28
Joined
Jul 6, 2006
Messages
20
Corrected Code

You weren't doing much wrong, try this amended code :-

Dim rst As DAO.Recordset

Set rst = CurrentDb.OpenRecordset("description")

Do Until rst.EOF

If rst![Element_Label] Like "3*" Then
rst.Edit
rst![sys] = 3
rst.Update
End If

rst.MoveNext

Loop
 

Users who are viewing this thread

Top Bottom