Using a Command Button to Unmark all Records in a Subform

  • Thread starter Thread starter Diane Mountford
  • Start date Start date
D

Diane Mountford

I'm working on a functionality that allows users to request file
labels for certain objects in the database. There are currently two
ways of requesting a label, and I've created a Union query to put all
the requests into one list. But when the labels are printed, it is
impossible to uncheck the request control, since the query is
unmodifiable. So I've created a form that has two subforms, one for
each source of requests, which will allow users to uncheck the records
for the completed labels. So far the system works great, but ...

I would like to add an "uncheck all" button to this form, but am not
sure how to go about coding it. Should I use some sort of For ... Each
loop (and if so, how do I deal with the subforms?) or an update Query
(and if so, how?) or something else I haven't yet thought of?

Any help would be much appreciated.

Cheers,
Diane
 
I'm working on a functionality that allows users to request file
labels for certain objects in the database. There are currently two
ways of requesting a label, and I've created a Union query to put all
the requests into one list. But when the labels are printed, it is
impossible to uncheck the request control, since the query is
unmodifiable. So I've created a form that has two subforms, one for
each source of requests, which will allow users to uncheck the records
for the completed labels. So far the system works great, but ...

I would like to add an "uncheck all" button to this form, but am not
sure how to go about coding it. Should I use some sort of For ... Each
loop (and if so, how do I deal with the subforms?) or an update Query
(and if so, how?) or something else I haven't yet thought of?

Diane,

try this code in the button's OnClick event procedure:

Dim rs As DAO.Recordset

'Grab the records from the updatable subform
Set rs = Me![NameOfSubformControlForUnchecking].Form.RecordsetClone

rs.MoveFirst
'Process all records
Do Until rs.EOF
'Set the request flag to False
rs.Edit
rs![RequestField] = False
'Save the change
rs.Update

'Go to the next record
rs.MoveNext
Loop

'Clean up before leaving
rs.Close
Set rs = Nothing

'Update the subform on the screen
Me![NameOfSubformControlForUnchecking].Form.Requery

Please note: I assumed the command button is on the main form.

HTH

Best regards
Emilia

Emilia Maxim
PC-SoftwareService, Stuttgart
http://www.maxim-software-service.de
 
Back
Top