Form Filters and Checkbox - Select all

razorking

Registered User.
Local time
Yesterday, 19:56
Joined
Aug 27, 2004
Messages
332
I have a form, based upon a query that has multiple fields. One of the fields is a yes/no field with a checkbox on the form. I was wondering if it was possible to set the checkbox to yes based upon or after the filtering of the other form fields?

In my example I am using Access 2007. So say I right click in the state field on a California entry on the form and I say - equals CA - to filter to those records. Then I right click on a San Diego entry in the city field and again select - equals San Diego. Now my form is filtered to all records with a state of Ca and a city of San Diego. Now can I have a button that when clicked will update all the yes/no checboxes to Y??

Thanks!
 
You can using recordsetclone

Code:
''Dec Var
    Dim rst As DAO.Recordset
''Clone the forms recordset - keeps filters
    Set rst = Me.RecordsetClone
''See how many records are in the set
    Debug.Print rst.RecordCount
''GoTo first record
    rst.MoveFirst
''Loop through all records
    Do Until rst.EOF
        With rst
''Edit the record
            .Edit
''Set the data
            !YourCheckBox = True
''Update the record
            .Update
        End With
''GoTo Next Record in recordset
    rst.MoveNext
    Loop

Hope my comments make sense!
 
Hope my comments make sense!

Well it must make sense because I added a button to the form and pasted your code into the on click event property of the button, changed the reference to my checkbox and it works great.

This is very cool.

Thank you!!
 
Well it must make sense because I added a button to the form and pasted your code into the on click event property of the button, changed the reference to my checkbox and it works great.

LOL - Glad it worked
You can do some great stuff with the RecordsetClone to control forms etc
Look it up, well worth learning
 

Users who are viewing this thread

Back
Top Bottom