Results 1 to 15 of 15
  1. #1
    Triland's Avatar
    Triland is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jan 2013
    Posts
    37

    Select All Button


    Hi: I have a Form with several lines of information. The user is able to select each row of information that they would like to have added to the final report. I want to create a button that will allow the end-user to select or de-select all by clicking the button. Does anyone know how I might do that and what the code or macro would look like?

  2. #2
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    Is your information in a list box or in a subform?

  3. #3
    Triland's Avatar
    Triland is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jan 2013
    Posts
    37
    It is in a simple select:

    Triland 213232 USE = Checkbox (val = true)
    Zena 315433 USE = Checkbox (val = true)

    so if you select ten boxes then only those records will appear in the final report. I just want to be able to have a "master" button that will allow me to select or deselect them all. I hope that's clearer.

  4. #4
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    that doesn't answer my question.

    Are the checkboxes on a form, a subform or in a listbox?

    If they are on a form they are all part of one record on one table
    if they are in a subform they are a collection of items in a one to many relationship
    if they are in a list box it could be either

    This:
    Triland 213232 USE = Checkbox (val = true)
    Zena 315433 USE = Checkbox (val = true)

    means nothing in terms of solving your problem because you have said nothing about how your form is set up.

  5. #5
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,016
    Is this what you're talking about?
    To Tick Checkbox on All Records
    Code:
    Private Sub TickCheckBoxAllRecords_Click()
    
    Dim db As DAO.Database
    Dim rs As DAO.Recordset
    
    Set db = CurrentDb
    Set rs = db.OpenRecordset("YourTableName")
    Do While Not rs.EOF
    rs.Edit
    rs!CheckBoxName = -1
    rs.Update
    rs.MoveNext
    Loop
    
    rs.Close
    Set rs = Nothing
    Me.Requery
    End Sub


    To Clear Checkbox on all Records
    Code:
    Private Sub ClearCheckBoxAllRecords_Click()
    
    Dim db As DAO.Database
    Dim rs As DAO.Recordset
    
    Set db = CurrentDb
    Set rs = db.OpenRecordset("YourTableName")
    Do While Not rs.EOF
    rs.Edit
    rs!CheckBoxName = 0
    rs.Update
    rs.MoveNext
    Loop
    
    rs.Close
    Set rs = Nothing
    Me.Requery
    End Sub

    Replace CheckBoxName with the actual name of your Checkbox

    Replace YourTableName with the actual name of your Table or Query.

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  6. #6
    Triland's Avatar
    Triland is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jan 2013
    Posts
    37
    They are the checkboxes on a form.

  7. #7
    Triland's Avatar
    Triland is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jan 2013
    Posts
    37
    In case of checkboxes on a form would the code above still work. Or would I add something to the "On Click" action of the button to have it perform a select all?

  8. #8
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,016
    The code has to be done on a Form! There is no need for a 'select all,' becuase the code is looping through all of the Records in the current Form's RecordSource.

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  9. #9
    alcapps is offline Competent Performer
    Windows 8 Access 2010 32bit
    Join Date
    Jan 2012
    Posts
    292
    can you post your form in a database so we can help you?

  10. #10
    Triland's Avatar
    Triland is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jan 2013
    Posts
    37

    Select All or Deselect All

    As requested I have attached the database. Once you open the Form you will see where you have the option to select one record at a time. I want to add an option to selectall or deselectall. This will make it so the end-user does not have to go through the deselect previously selected records.
    Attached Files Attached Files
    Last edited by Triland; 02-01-2013 at 12:58 PM. Reason: Spelling

  11. #11
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,016
    Quote Originally Posted by alcapps View Post
    can you post your form in a database so we can help you?
    I've already given the OP a step-by-step that only requires him to change the names involved to get it to work!

    • Create a Command Button in the Header of your Form
    • Name it cmdSelectAll
    • Place this code in its OnClick event

    Code:
    Private Sub cmdSelectAll_Click()
    Dim rs As DAO.Recordset
    
    Set db = CurrentDb
    Set rs = db.OpenRecordset("Master Cable Code Table (TRI)")
    Do While Not rs.EOF
    rs.Edit
    rs!USE = -1
    rs.Update
    rs.MoveNext
    Loop
    
    rs.Close
    Set rs = Nothing
    Me.Requery
    End Sub

    Now, for a deselect button

    • Create another Command Button in the Header of your Form
    • Name it cmdDeselectAll
    • Place this code in its OnClick event

    Code:
    Private Sub cmdDeselectAll_Click()
    Dim rs As DAO.Recordset
    
    Set db = CurrentDb
    Set rs = db.OpenRecordset("Master Cable Code Table (TRI)")
    Do While Not rs.EOF
    rs.Edit
    rs!USE = 0
    rs.Update
    rs.MoveNext
    Loop
    
    rs.Close
    Set rs = Nothing
    Me.Requery
    
    End Sub


    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  12. #12
    alcapps is offline Competent Performer
    Windows 8 Access 2010 32bit
    Join Date
    Jan 2012
    Posts
    292
    you could use this it would allow you to use the same code and if you want to call more than one field you could use the same code.
    This is based on the code from the last post..

    Hope this helps..

    private Sub cmdDeselectAll_Click()
    setCheckedValue "USE", 0
    me.requery
    end Sub

    private Sub cmdSelectAll_Click()
    setCheckedValue "USE", -1
    me.requery
    end sub

    private sub setCheckedValue (datField as string, datInt as Integer)
    dim db as DAO.Database
    dim rst as DAO.Recordset

    set db = currentdb()

    set rst = db.openrecordset("Master Cable Code Table (TRI)", dbopendynaset)
    Do while Not rst.eof
    rst.edit
    rst(datField) = datInt
    rst.Update
    rst.MoveNext
    Loop

    rst.close
    Set rst = Nothing
    end sub

  13. #13
    Triland's Avatar
    Triland is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jan 2013
    Posts
    37
    I am adding the coding from missinlinq exactly as I am told. 1. Create the button 2. in Properties under OnClick, I add the code as outlined above. The system tells me I enterred invalid syntax and/or simply doesn't run. Pleae pardone me, but might I ask you to update the database I sent out and send it back to me? That way I can see what I'm doing wrong and learn how to do it right.

  14. #14
    alcapps is offline Competent Performer
    Windows 8 Access 2010 32bit
    Join Date
    Jan 2012
    Posts
    292
    SelectAll.zip

    hope this helps.. a little different twist..

  15. #15
    Triland's Avatar
    Triland is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jan 2013
    Posts
    37
    OK ... That was awesome!!!!! I guess I need to learn a little more about how to use coding. I will mark this resolved.

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

Similar Threads

  1. Use Toggle button to select subform value
    By DerekAwesome in forum Forms
    Replies: 7
    Last Post: 12-02-2012, 07:15 PM
  2. Replies: 3
    Last Post: 08-19-2012, 12:12 PM
  3. multi-select listbox and new entry button
    By user622 in forum Forms
    Replies: 2
    Last Post: 07-05-2011, 09:14 AM
  4. Radio Button Select in WebBrowser
    By access_man in forum Access
    Replies: 3
    Last Post: 10-27-2010, 05:29 PM
  5. Select Radio Button and another one turns off
    By Lockrin in forum Programming
    Replies: 1
    Last Post: 02-09-2010, 02:17 PM

Tags for this Thread

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