Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

update field in Recordset 2

Status
Not open for further replies.

Bullsandbears123

Technical User
Feb 12, 2003
291
US
How do I update a field within a recordset

my code states I need "edit" when run

Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim current As String


Set db = CurrentDb()
Set rst = db.OpenRecordset("mytable")
rst.MoveFirst


'set value in fields
Do While Not rst.EOF
If rst.Fields(1) = DatePart("m", Date) Then
rst.Fields(3).Value = True 'this does not work
Else
rst.Edit.Fields(3).Value = False 'This does not work
End If

rst.MoveNext
Loop
 
You have to open the record by using .edit, write the data, then update the record with .update. I'd do it something like this:

dim x as boolean
Do While rst.EOF=False
If rst.Fields(1) = DatePart("m", Date) Then
x=True
else
x=false
end if

rst.edit
rst.fields(3).value=x
rst.update
rst.MoveNext
Loop
 
'set value in fields
rst.Edit
Do While Not rst.EOF
If rst!myfield = DatePart("m", Date) Then
rst.myfield = True 'this does not work
Else
rst!myfield = False 'This does not work
End If

rst.Update
rst.MoveNext
Loop

Use the dot operator for compile time known objects/properties and the bang operator for compile time unknowns such as field names.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top