Results 1 to 8 of 8
  1. #1
    Kipandrews06 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Oct 2021
    Posts
    54

    Need to make Continuous Form multiple checkbox selections deselect

    I am making a database for inventory that we store in a warehouse for our clients. I want our clients to be able to log on and I have a continuous form where they can check a checkbox for whatever product(s) they want to have shipped out. Once you click on a command button at the bottom after you make all your selections, it will transfer those selected records to a "shopping cart" or "basket" form with all those records showing with the quantities, etc. So the problem I'm having is I need to be able to clear or "deselect" all the checkboxes on the first form. Everything I've tried only clears or unchecks the last selection I checked and not every record on the continuous form. I'm trying to use a command button on the bottom of the page to do this, but if there is a better way to do I'm all ears. Any help with this would be greatly appreciated. This is my code so far for the command button, it does uncheck a selection, but it inly does the last selection I did and not the whole form.

    Code:
    Private Sub cmdUndo_Click() 'Purpose:   Clear all the check box values.
        Dim ctl As Control
        
     'Clear all the controls for the Check Box.
        For Each ctl In Me.Controls
            If ctl.ControlType = acCheckBox Then
                ctl.Value = False
            End If
        Next ctl
            
        
    End Sub


  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,524
    run an update query to set field = false.

  3. #3
    Kipandrews06 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Oct 2021
    Posts
    54
    How do I run an update query?

  4. #4
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,914
    How many checkboxes are on each record?
    That code is for multiple checkboxes on a record?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  5. #5
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,791
    The only way to individually check/uncheck boxes on a continuous form is if the checkbox control is bound to a query or table field. The value of the check then becomes a field value for each record in that field. You can use button click code to alter the box values as ranman said, BUT if you need the value of the control/field to make up an order and have clicked the button it could be that your selections are all gone and the order is empty.

    There are many ways you could design this but if you stick with your approach just make sure the loss of the selected checks will not affect your order process. Perhaps commit the order and on the main form, set it back to how it was when it opened. I'm guessing it opens to a new record and the form's Data Entry property is set to True/yes. I suggest that you Google ms access currentdb.Execute to find examples of how to run action sql without getting a warning prompt from Access.
    Last edited by Micron; 01-19-2022 at 09:39 AM. Reason: added info
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  6. #6
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,114
    Usually when dealing with a subform is better to loop through the subform's recordset instead of running an update query as the subform might be filtered so you would need to reset the criteria for the update query. Here is an example on how to set all checkboxes to False (bound to a yes\no field holding your Selected value):
    Code:
    Private Sub cmdUndo_Click() 'Purpose:   Clear all the check box values.'Dim ctl As Control
        
    'Clear all the controls for the Check Box.
        'For Each ctl In Me.Controls
            'If ctl.ControlType = acCheckBox Then
                'ctl.Value = False
            'End If
        'Next ctl
            
    Dim rs as DAO.Recordset
    
    
    
    
    Set rs=Me.RecordsetClone
    If rs.recordcount=0 then Exit sub
    rs.MoveFirst  'reset to first record
    Do Until rs.EOF
        rs.Edit
        rs("YourYesNo_Selected_Field")=False 'note you need to use the IsSelected field or what ever you named your Yes\No field not the control name bound to it
        rs.Update
    rs.MoveNext
    Loop
    rs.Close
    Set rs=Nothing
    'Refresh the form
    Me.Refresh    
    
    
    End Sub
    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  7. #7
    Kipandrews06 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Oct 2021
    Posts
    54
    My continuous form only has one checkbox called Select which is bound. But since its a continuous form, it shows all the records and you can scroll down and click on the checkbox for whatever item they want shipped out. I ended up figuring it out after looking at the currentDb.Execute example micron recommended. I tried this code and it worked like a charm! Thank you all for the help!

    Code:
    Private Sub cmdUndo_Click() CurrentDb.Execute "UPDATE [Products] SET [Select]= False", dbFailOnError
     Me.Requery
            
    End Sub

  8. #8
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,114
    Glad to see you got it working, just keep in mind that the update query will update all records in the table, not just the ones loaded in the subform.

    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

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

Similar Threads

  1. Replies: 6
    Last Post: 01-18-2022, 04:29 AM
  2. Replies: 5
    Last Post: 12-27-2017, 04:21 AM
  3. Write Conflict By Checkbox In Continuous Form
    By Wappervliegje in forum Access
    Replies: 9
    Last Post: 11-14-2017, 04:49 AM
  4. Continuous Form With Checkbox VB Problem
    By WhiskyLima in forum Access
    Replies: 4
    Last Post: 11-25-2013, 08:25 AM
  5. Replies: 2
    Last Post: 10-09-2012, 10:07 AM

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