How to mark all records on a form?

  • Thread starter Darrell Childress
  • Start date
D

Darrell Childress

I have a form showing data in "Continuous Forms" mode. One of the fields
is a checkbox. I was trying to write a macro that will set the value of
the checkbox (Processed) to Yes (-1). On the Form header I put a button
that runs the macro. However, it only updates the value of the first
record shown. If I move the cursor to another record, it will update
that one. How do I make it update all records on the form?
Thanks,
Darrell
 
A

Allen Browne

It may be easier to execute an Update query statement on the subform's
table, and then Requery the form, but this should work:

If Me.Dirty Then
Me.Dirty = False
End If
With Me.RecordsetClone
If .RecordCount > 0 Then
.MoveFirst
Do While Not .EOF
If !Processed = False Then
.Edit
!Processed = True
.Update
End If
.MoveNext
Loop
End If
End With
 
D

Darrell Childress

Thank you Allen. Actually, I had already written an Update Query to do
that exact thing. I went ahead and tried your code and it works
perfectly and is faster than the update query, so I will implement your
solution. One question for future reference: What do the first 3 lines
do? --- If Me.Dirty Then
Me.Dirty = False
End If
Thanks again,
Darrell
 
A

Allen Browne

You will find that Access sets the form's Dirty property to True if it needs
saving, i.e. you have already started typing something or assigned a value
to a control programmatically, and it has not yet been saved. The code
forces the record to save.

If it did not do that, you would get a conflict when you updated the same
record in the RecordsetClone.
 
D

Darrell Childress

Ahhh, makes sense. I probably should have looked that one up. Thanks for
your wisdom.
 
Top