Results 1 to 7 of 7
  1. #1
    Tommo is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Sep 2015
    Posts
    42

    Clear all checkboxes on form

    Hi,

    Please see the attached screenshot of my vba.

    Basically the form on the left is generated when i create a new class term. I then want to tick the classes that are being added to the new term and when i hit the button it needs to;

    Save (To update the table)
    Run the append query. (To add them to the new term)
    Clear all the checkboxes.
    Save again
    Close.

    Sometimes it works. Most of the time it works on all but the last checkbox i check.

    ie If i check 5 boxes it will only append 4 and only clear 4.

    Been working on this for ages. Any help please.

    Click image for larger version. 

Name:	Screenshot 2015-10-08 21.06.37.jpg 
Views:	18 
Size:	89.6 KB 
ID:	22342

  2. #2
    ranman256's Avatar
    ranman256 is online now VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    If these check boxes are unbound on a form,
    make a routine for them all. Don't uncheck 4 of 5, just uncheck them all. ChkBox1.value = false.

    If they are fields (bound) then run 1 single update query.

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,921
    ranman, I expect there is one bound checkbox otherwise all records would have same value when checked/unchecked.

    Can't read the code in the image. Copy/paste code into post. Use CODE tags to retain indentation.

    Probably, the record for the last checkbox checked must first be committed to table. This happens when move to another record, close form, or run code. One method: DoCmd.RunCommand acCmdSaveRecord
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  4. #4
    Tommo is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Sep 2015
    Posts
    42
    So the checkboxes are bound to a field in the table the form relates to.
    The query checks for true values on this field and then appends, adding 1 to the term. Hence adding to the new term.
    That's why i need the values changed to false once it has run.


    Sorry didnt check the image.

    Code:
    Private Sub cmdPassToNewTerm_Click()
    
    DoCmd.Save
    DoCmd.OpenQuery "qryAddClassesToNewTerm", , acEdit
    
        Dim i As Integer
        
        Dim db As Database
        Dim rs As Recordset
        Dim ClassNumberOfRecords As Long
        
        Set db = CurrentDb
        Set rs = db.OpenRecordSet("tblClasses")
      
        ClassNumberOfRecords = DCount("ClassID", "tblClasses")
      
                rs.MoveLast
                rs.MoveFirst
                
                For i = 0 To ClassNumberOfRecords - 1
                    If rs.Fields("Copy") = True Then
                        rs.Edit
                        rs.Fields("Copy") = False
                        rs.Update
                    End If
                    
                rs.MoveNext
                Next I
            
        rs.Close
        Set rs = Nothing
        db.Close
        
    DoCmd.Save
    DoCmd.RefreshRecord
    
    
    DoCmd.Close
    
    
    
    
    End Sub

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,921
    Did you try the suggestion about first committing record?

    I think DoCmd.Save has nothing to do with saving record.

    Do you just want to set all records in table back to False? Instead of looping recordset, could:

    CurrentDb.Execute "UPDATE tblClasses SET Copy=False"

    Is this a multi-user database? Could there be conflicts between users checking/unchecking this field?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  6. #6
    Tommo is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Sep 2015
    Posts
    42
    In theory it doesnt have to be a multi user db. We will see in practice if people can do as they are told.

    Will try your suggestion

  7. #7
    Tommo is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Sep 2015
    Posts
    42
    Quote Originally Posted by June7 View Post
    Did you try the suggestion about first committing record?

    I think DoCmd.Save has nothing to do with saving record.

    Do you just want to set all records in table back to False? Instead of looping recordset, could:

    CurrentDb.Execute "UPDATE tblClasses SET Copy=False"

    Is this a multi-user database? Could there be conflicts between users checking/unchecking this field?
    Yeh that works. Thanks man.

    FFS i spent ages working out all that RS shit.


    lol

    Thanks.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. How to loop through all checkboxes on form?
    By archaeofreak in forum Programming
    Replies: 9
    Last Post: 09-16-2013, 01:55 PM
  2. clear form
    By slimjen in forum Forms
    Replies: 1
    Last Post: 05-16-2012, 02:53 PM
  3. How to clear the form?
    By Mrcams in forum Access
    Replies: 3
    Last Post: 01-03-2011, 12:15 AM
  4. Clear all checkboxes?
    By thekruser in forum Forms
    Replies: 2
    Last Post: 09-16-2010, 09:50 AM
  5. Disable Checkboxes for a row in Form
    By seshan in forum Programming
    Replies: 1
    Last Post: 02-05-2010, 07:36 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums